I Am unable to take screen shot

599 views
Skip to first unread message

Karunanidhi Ethiraj

unread,
May 8, 2014, 9:08:44 AM5/8/14
to seleniu...@googlegroups.com

Hi,

 

I Am unable to take screen shot

 

 

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

      OutputType cannot be resolved to a variable

      The method copyFile(File, File, boolean) is undefined for the type FileUtils

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 

Shawn McCarthy

unread,
May 8, 2014, 12:09:21 PM5/8/14
to seleniu...@googlegroups.com, karuna...@teledatamarine.com
Did you import OutputType ? From your screenshot, click the first row in the quick fixes menu.

Lan Ta Bao

unread,
May 8, 2014, 9:58:45 PM5/8/14
to seleniu...@googlegroups.com, karuna...@teledatamarine.com
Nhp mã vào đây...package com.bp.pablo.util;

import java.io.File;
import java.io.IOException;
import com.bp.pablo.util.CmgiumMethod;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;


public class TakeScreenShot {
private static WebDriver driver;
public static final String PROP_PROJECT_BUILD_DIR = "project.build.directory";
public static final String TEST_PACKAGE = "test.package";
public static void init(WebDriver d) {
driver = d;
}
public static void takeScreenshoot(String name) {
CmgiumMethod currentTestMethod = getCurrentTestMethod();
// skip take screenshot if could not found current test method execute
if (currentTestMethod == null) 
return;
String screenshootDir = PropertiesHelper.getKey(PROP_PROJECT_BUILD_DIR)
+ File.separator + "screenshots" + File.separator
+ currentTestMethod.getClassName();
File f = new File(screenshootDir);
if (!f.exists() || !f.isDirectory()) {
f.mkdirs();
}
File output = null;
File file;
try {
if (name == null || name.length() == 0) {
File[] files = f.listFiles();
int count = 0;
if (files != null && files.length > 0) {
for (File fl : files) {
if (fl.getName()
.startsWith(currentTestMethod.getName())) {
count++;
}
}
}
name = currentTestMethod.getName()
+ (count == 0 ? "" : (" (" + count + ")"));
}
output = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
file = new File(screenshootDir, name + ".png");
FileUtils.moveFile(output, file);
} catch (IOException e) {

}
}

public static void takeScreenshoot() {
takeScreenshoot("");
}

public static CmgiumMethod getCurrentTestMethod() {
String testPackge = PropertiesHelper.getKey(TEST_PACKAGE);
final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
for (int i = 0; i < ste.length; i++) {
String className = ste[i].getClassName();
String methodName = ste[i].getMethodName();
if (className.startsWith(testPackge)) {
CmgiumMethod method = new CmgiumMethod();
method.setClassName(className);
method.setName(methodName);
return method;
}
}
return null;
}
}


this is my script that allow me to take any screentshot by Selenium


Vào 20:08:44 UTC+7 Thứ năm, ngày 08 tháng năm năm 2014, Karunanidhi Ethiraj đã viết:

Karunanidhi Ethiraj

unread,
May 9, 2014, 1:32:03 AM5/9/14
to Lan Ta Bao, seleniu...@googlegroups.com

Dear Lan,

 

Below code is showing very large, I want to simple method and to take screen shot easy. Can u please provide the simplest code?

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 

Krishnan Mahadevan

unread,
May 9, 2014, 2:12:00 AM5/9/14
to Selenium Users
Karunanidhi,

What is stopping you from simplifying that code ? I am very sure that you aren't expecting someone else to provide you with an actual implementation which you could just copy paste and use off! That would be as good as asking someone else to do the job for you no ?


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/E0A323AEEF92404F97E81B64A2D0236D025ADF11AADB%40souexmb01.TDGLOBAL.INTRA.
For more options, visit https://groups.google.com/d/optout.

Karunanidhi Ethiraj

unread,
May 9, 2014, 2:44:56 AM5/9/14
to seleniu...@googlegroups.com

TO KRISHNA,

 

NOT LIKE THAT I HAVE TRIED CODE WHICH IS PROVIDED EARLIER, BUT ITS NOT WORKING THEREBY I HAVE ASKED TO UNDERSTAND EASY METHOD.

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 

Krishnan Mahadevan

unread,
May 9, 2014, 2:55:28 AM5/9/14
to Selenium Users
First things first.

Mail ethics say "When someone types an email in CAPS, it normally means they are irked". So going by that, it sounds like you are irked! 
Getting worked up, doesnt go anywhere in terms of getting answers on forums ! So good luck with your anger because you didnt get a "readily consumable code" from me!

You had a compilation error in your original code. Compilation errors are normally things that come up because of a messed up CLASSPATH. This is the rudiments of java programming and it is going to come everytime you try referring to a class that's either NOT in your source code or in your referenced jars and this problem has got nothing to do with Selenium/WebDriver for that matter !
So what did you do to get that sorted out ? Did you try peeking into the jars that are part of your "Referenced libraries" and check if it contains org.openqa.selenium.OutputType<T> interface ?





Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


Karunanidhi Ethiraj

unread,
May 9, 2014, 3:20:44 AM5/9/14
to seleniu...@googlegroups.com

Krinshna,

 

 below is the error  unable to solve myself. Getting confuse.

 

 

 

 

Lan Ta Bao

unread,
May 9, 2014, 3:41:53 AM5/9/14
to seleniu...@googlegroups.com, karuna...@teledatamarine.com
Step 1 : download apache commons io

Step 2 : import file jar to your project

Step 3 : in you main : import org.apache.commons.io.FileUtils;

Step 4 : Run and if have an error please take screenshot all your main.

Afzal

unread,
May 9, 2014, 3:57:45 AM5/9/14
to seleniu...@googlegroups.com, karuna...@teledatamarine.com
File ScreenShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(ScreenShot, new File("C:\\Temp"));

Karunanidhi Ethiraj

unread,
May 9, 2014, 4:17:18 AM5/9/14
to seleniu...@googlegroups.com

Dear Lan/shaik,

 

Many thanks. The code is working correctly.

 

To Krishna,

 

Now I have got clear and taken screen shot.

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 


From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Lan Ta Bao


Sent: Friday, May 09, 2014 1:12 PM
To: seleniu...@googlegroups.com
Cc: Karunanidhi Ethiraj

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Karunanidhi Ethiraj

unread,
May 9, 2014, 5:00:12 AM5/9/14
to Afzal, seleniu...@googlegroups.com

Dear  Afzal,

 

Many thanks Its working fine.

 

Please see the below screen shot, I am unable to click the button. Even I have use id, css, xpath and link values.

 

driver.findElement(By.cssSelector("a[href=\"javascript:AddNew(document.frmEmployee)\"]")).click();

 

driver.findElement(By.xpath(".//*[@id='divsmtoolbar']/table/tbody/tr/td[3]/span[1]/a/img")).click();

 

driver.findElement(By.cssSelector("add.png")).click();

 

driver.findElement(By.xpath("/html/body/form/div/table/tbody/tr/td[3]/span/a/img")).click();

 

 

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 


From: Afzal [mailto:shaik.afz...@gmail.com]

Sent: Friday, May 09, 2014 1:28 PM
To: seleniu...@googlegroups.com
Cc: Karunanidhi Ethiraj

Afzal Hussain Shaik

unread,
May 9, 2014, 5:11:05 AM5/9/14
to Karunanidhi Ethiraj, seleniu...@googlegroups.com
Hi,


driver.findElement(By.xpath("//td[@class='SMToolBarThirdCell']/span[1]")).click();

try the above code, if it doesn''t work let me know.

Regards,
Afzal
--
Thanks & Regards,
Afzal Hussain Shaik

Lan Ta Bao

unread,
May 9, 2014, 5:13:14 AM5/9/14
to seleniu...@googlegroups.com, Afzal, karuna...@teledatamarine.com
Have you try with Selenium IDE ?

If not , open your firefox and download it in this link .

Selenium IDE is very helpful to us to find element by tools then combine this to java class.

Karunanidhi Ethiraj

unread,
May 9, 2014, 5:16:25 AM5/9/14
to Afzal Hussain Shaik, seleniu...@googlegroups.com

Hi Afzal,

 

Still error is existing.

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 

Karunanidhi Ethiraj

unread,
May 9, 2014, 5:59:42 AM5/9/14
to Lan Ta Bao, seleniu...@googlegroups.com, Afzal

Dea Lan,

 

I have tried the element finding in IDE  its correctly fetching, but if we copy and paste the same source code into the web driver its not working.

 

 

driver.findElement(By.xpath("div[@id='divsmtoolbar']/table/tbody/tr/td[3]/span[1]/a/img")).click();

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head profile="http://selenium-ide.openqa.org/profiles/test-case">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="selenium.base" href="http://smdev1/" />

<title>New Test</title>

</head>

<body>

<table cellpadding="1" cellspacing="1" border="1">

<thead>

<tr><td rowspan="1" colspan="3">New Test</td></tr>

</thead><tbody>

<tr>

            <td>open</td>

            <td>/gmsuat/</td>

            <td></td>

</tr>

<tr>

            <td>selectWindow</td>

            <td>name=fbMainContainer</td>

            <td></td>

</tr>

<tr>

            <td>click</td>

            <td>id=fbInspectButton</td>

            <td></td>

</tr>

<tr>

            <td>selectWindow</td>

            <td>name=iframecontentpanel</td>

            <td></td>

</tr>

<tr>

            <td>click</td>

            <td>//div[@id='divsmtoolbar']/table/tbody/tr/td[3]/span[1]/a/img</td>

            <td></td>

</tr>

<tr>

            <td>clickAndWait</td>

            <td>//div[@id='divsmtoolbar']/table/tbody/tr/td[1]/span[1]/a/img</td>

            <td></td>

</tr>

 

</tbody></table>

</body>

</html>

 

 

 

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 

Afzal Hussain Shaik

unread,
May 9, 2014, 6:08:36 AM5/9/14
to Karunanidhi Ethiraj, Lan Ta Bao, seleniu...@googlegroups.com
will it be possible to send View source code to us.

right click on page and choose view source > copy that code in txt file and send to us

if any security issue, please ignore

Regards,
Afzal

Vishi

unread,
May 9, 2014, 8:37:38 AM5/9/14
to seleniu...@googlegroups.com, karuna...@teledatamarine.com
better you try with identifier XPATH for the element which you are unable to find.

You can get XPATH from FireBug -> Firepath, if you are using FF.

try this.....

Vishi

unread,
May 9, 2014, 8:47:44 AM5/9/14
to seleniu...@googlegroups.com, karuna...@teledatamarine.com
hi Karunanidhi,

Try the below code to get screen shot... I hope this will help you in understanding why you are not getting the screenshot...

package one;

import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class GmailScreenshot{

      static WebDriver driver = new FirefoxDriver();
     
@BeforeTest
public static void browser() throws Exception{
    driver.get("https://www.gmail.com");   
    driver.manage().window().maximize();
    }
   
@Test
      public void testAddEmp() throws Exception
      {
          try{
// give wrong Username / Wrong pwd, then you will get screenshot....             
              driver.findElement(By.id("Email")).sendKeys("abcdef");
              driver.findElement(By.id("Passwd")).sendKeys("abcdef");
              driver.findElement(By.id("signIn")).click();
             
//    clickcing on Compose button...         
              driver.findElement(By.xpath(".//*[@id=':hj']/div/div")).click();
             
          }
            catch(Exception e)
            {
                File screenShot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenShot, new File("give your locatiobn path"));
            }
      }

    @AfterMethod
      public void tearDown() throws Exception {
      driver.quit();
       
      }
    }


Thanks,
Vishnu


On Thursday, May 8, 2014 6:38:44 PM UTC+5:30, Karunanidhi Ethiraj wrote:

vibhu kinger

unread,
May 9, 2014, 9:53:33 AM5/9/14
to seleniu...@googlegroups.com
Hi, 
Plz try with javascript!
WebElement element=driver.findElement(By.xpath("whatever..."));
JavaScriptExecutor js=(JavaScriptExecutor)driver;
js.executeScript("arguments[0].click();",element);


Regards
Vibhu

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Karunanidhi Ethiraj

unread,
May 11, 2014, 11:44:54 PM5/11/14
to Vishi, seleniu...@googlegroups.com

Hi Vishi,

 

I have taken the screen shot, but the button click is still issue.

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611/ 9443038011

E karuna...@teledatamarine.com

W  www.teledatamarine.com

 

 


From: Vishi [mailto:kvv...@gmail.com]

Sent: Friday, May 09, 2014 6:18 PM
To: seleniu...@googlegroups.com
Cc: Karunanidhi Ethiraj

Reply all
Reply to author
Forward
0 new messages