I have been attempting to click the confirm logout button for so long and I can not get it to work! I have a test that is supposed to log you out and return to the homepage as soon as it exits, but I cant seem to click the button. When I attempt to switch to the pop up frame using
driver.switchTo().frame(0);
It runs and does not give me any errors... however I can not get it to locate the confirm logout!
i faced the same problem and solved it by searching the frame with XPATH. Maybe this snippet helps you out:
wd = your WebDriver;
searchFrame= wd.findElement(By.xpath("whatever"));
wd.switchTo().frame(searchFrame);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("button2")));
wd.findElement(By.className("button2")).click();
You haven't provided the HTML code for the iframe, but, given what we have, we can locate the iframe that contains the provided log out button:
WebElement frame = driver.findElement("//iframe[.//a[contains(@id, 'confirmLogoutDialog')]]");
driver.switchTo.frame(frame);
Then, you may locate your button by link text and click it:
driver.findElement(By.linkText("Sign Out")).click();
You may also need to wait for it to become clickable:
WebDriverWait wait = WebDriverWait(driver, 10);
WebElement logout = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Sign Out")));
logout.click();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.