简体   繁体   English

弹出框-如何使用硒处理

[英]Pop up box - how to handle it in selenium

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! 它可以运行并且不会给我任何错误...但是我无法找到它来确认注销! 弹出框

这是弹出框的ID

这是退出按钮标签

i faced the same problem and solved it by searching the frame with XPATH. 我遇到了同样的问题,并通过使用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: 您尚未提供iframe的HTML代码,但是,鉴于我们所拥有的,我们可以找到包含所提供的注销按钮的iframe:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM