Selenium WebDriver Yahoo mail sign out error

2019-08-25 19:02发布

I'm new to Selenium WebDriver and I am trying to write a simple script to log into a yahoo email account and then logout. I have managed to get the login part work working but I haven't been able to get the sign out part to work. I get the following error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate
element: {"method":"link text","selector":"Sign Out"}

I have tried the following 3 things so far: 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();

I essentially get the same error in each case. I have pasted my code below. Any help would be appreciated.

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

2条回答
倾城 Initia
2楼-- · 2019-08-25 19:30

Use the script below, it will work:

Actions actions = new Actions(driver);
WebElement m1 = driver.findElement(By.linkText("Sign out"));
actions.moveToElement(m1);
actions.click().build().perform();
查看更多
叼着烟拽天下
3楼-- · 2019-08-25 19:37

enter image description here

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();
查看更多
登录 后发表回答