web analytics
Google + RSS Feed

code for picture upload in google plus using selenium webdriver

0

January 18, 2014 by admin

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();

}

}


0 comments »

Leave a Reply

Your email address will not be published. Required fields are marked *


− one = 4

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts