Quality Testing

Quality is delighting customers

Hi Friends,

Below are my queries in selenium web driver

1. How to Upload a image using Selenium Web Driver.

2. How to take full page screen shot using selenium web driver.

3. How to Capture Dynamics ids or xpath using selenium web driver,

Please resolve above queries..

thanks

kalyan.

Views: 413

Reply to This

Replies to This Discussion

Try this sample code for upload a image..


public static void setClipboardData(String string) {
StringSelection stringSelection = new StringSelection(string);

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection,
null);
}
public static void main(String[] args) throws AWTException,
InterruptedException, MalformedURLException{
WebDriver driver;
driver = new FirefoxDriver();
String baseUrl = "http://gmail.com";
driver.get(baseUrl + "/");
driver.findElement(By.id("Email")).sendKeys("User1");
driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys("password1");
driver.findElement(By.id("signIn")).submit();
String parentWindowHandl = driver.getWindowHandle();
System.out.println("Parent " +parentWindowHandl);
driver.findElement(By.xpath("//*[@id='gb_119']/span[2]")).click();
Thread.sleep(8000);
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);

}
Locatable hoverIte = (Locatable)
driver.findElement(By.xpath("//*[@id='contentPane']/div/div[2]/div[1]/div[1]/div/div[8]/div[2]/span[1]"));


driver.findElement(By.xpath("//*[@id='contentPane']/div/div[2]/div[1]/div[1]/div/div[8]/div[2]/span[1]")).click();
Thread.sleep(5000);
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseMove(hoverIte.getCoordinates());
Thread.sleep(7000);
WebElement ai = driver.findElement(By.xpath("//div[@class='Ji rc dba']"));
ai.click();
//File file=new File("C:\\Users\\Public\\Pictures\\Sample
Pictures\\Desert.jpg"); URL url=file.toURL();
setClipboardData("C:\\home\\Desert.jpg");
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
driver.findElement(By.id("gbi4t")).click();
driver.findElement(By.id("gb_71")).click();
}
}

thanks for reply for above script is used for which scenario boss

Hi Kalyan,

1. How to Upload a image using Selenium Web Driver. A simple logic here is to use sendkeys and give the path of ur file in the browser field, it works. Try it on any social networking site or even on quality testing website to upload your pic. It works

2. How to take full page screen shot using selenium web driver. You can use- File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("C:\\Eclipse-Workspace\\SeleniumScreenshots\\something.jpg"));

3. How to Capture Dynamics ids or xpath using selenium web driver, You can use css locator in case if you are facing issues with changing xpath and ids. Also you can use customised xpaths like "starts-with or contains"

I hope this helps.

Cheers,

Sanj

Thanks for reply 

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service