WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://stackoverflow.com/");
driver.findElement(By.linkText("log in")).click();
driver.findElement(By.cssSelector("a.google.openid_large_btn")).click();
driver.findElement(By.id("Email")).sendKeys("username@gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("password");
driver.findElement(By.id("hlinks-user")).click();
driver.findElement(By.linkText("user2131252")).click();
Thread.sleep(3000L);
// None of these work to click on the upload button , actions, robot..
//driver.findElement(By.xpath(".//*[@id='change-picture']")).click();
//Actions actions = new Actions(driver);
//WebElement changepic = driver.findElement(By.xpath(".//*[@id='change-picture']"));
//actions.moveToElement(changepic).click().perform();
//actions.click();
//actions.perform();
/*Point coordinates = driver.findElement(By.xpath(".//*[@id='change-picture']")).getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates.getX(),coordinates.getY()+120);
//robot.mousePress(coordinates.getX());
driver.findElement(By.xpath(".//*[@id='change-picture']")).clear();
*/
Actions actions = new Actions(driver);
//for hovering over the username field
WebElement menuHoverLink = driver.findElement(By.xpath(".//*[@id='change- picture']"));
actions.moveToElement(menuHoverLink).perform();
//for clicking the logout link
WebElement logoutLink = driver.findElement(By.xpath(".//*[@id='change-picture']"));
logoutLink.click();
请我无法点击更改图片链接,我在不同的浏览器上收到不同的错误。
log4j:WARN 找不到记录器 (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) 的附加程序。log4j:WARN 请正确初始化 log4j 系统。线程“主”org.openqa.selenium.interactions.MoveTargetOutOfBoundsException 中的异常:元素无法滚动到视图中:(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:13 毫秒构建信息:版本:'2.33。 0',修订:'4e90c97',时间:'2013-05-22 15:33:32' 系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1' , java.version: '1.7.0_17' 会话 ID: 4534c06c-0622-4610-8d7d-1cf99f9577ee 驱动程序信息: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled =真,