我是Selenium WebDriver的新手,我正在尝试编写一个简单的脚本来登录雅虎电子邮件帐户,然后注销。我设法让登录部分工作,但我无法让登出部分工作。我收到以下错误:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate
element: {"method":"link text","selector":"Sign Out"}
到目前为止,我尝试了以下3件事: 1)
driver.findElement(By.linkText("Sign Out")).click();
2)
driver.findElement(By.partialLinkText("Sign Out")).click();
3)
WebElement element2 = driver.findElement(By.linkText("Sign Out"));
element2.submit();
在每种情况下,我基本上都会得到相同的错误。我在下面粘贴了我的代码。任何帮助将不胜感激。
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://login.yahoo.com/config/login_verify2?.intl=ca&.src=ym");
driver.manage().window().maximize();
WebElement element = driver.findElement(By.id("username"));
element.sendKeys("myid@yahoo.com");
driver.findElement(By.id("passwd")).sendKeys("mypassword");
element.submit();
Thread.sleep(40000);
driver.findElement(By.linkText("Sign Out")).click();
Thread.sleep(40);
答案 0 :(得分:3)
Mouse over
new Actions(driver).moveToElement(driver.findElement(By.id("yucs-profile_text"))).perform();
click Sign Out
driver.findElement(By.xpath("//a[contains(text(),'Sign Out')]")).click();
答案 1 :(得分:0)
使用下面的脚本,它将起作用:
Actions actions = new Actions(driver);
WebElement m1 = driver.findElement(By.linkText("Sign out"));
actions.moveToElement(m1);
actions.click().build().perform();