弹出框 - 如何在硒中处理它

时间:2015-08-20 13:35:26

标签: java xpath selenium-webdriver automation css-selectors

我一直试图点击确认注销按钮这么久,我无法让它工作!我有一个测试,应该会退出,并在退出后立即返回主页,但我似乎无法点击按钮。当我尝试使用

切换到弹出框架时
driver.switchTo().frame(0);

它运行并且没有给我任何错误...但是我无法找到确认注销! popup box

This is the pop up boxes id

This is the sign out button tag

2 个答案:

答案 0 :(得分:1)

我面临同样的问题,并通过XPATH搜索框架解决了这个问题。也许这个片段可以帮助你:

(?<!-)--(?!-)

答案 1 :(得分:0)

您尚未提供iframe的HTML代码,但是,鉴于我们拥有的内容,我们可以找到包含所提供的注销按钮的iframe:

WebElement frame = driver.findElement("//iframe[.//a[contains(@id, 'confirmLogoutDialog')]]");
driver.switchTo.frame(frame);

然后,您可以通过链接文本找到您的按钮并单击它:

driver.findElement(By.linkText("Sign Out")).click();

您可能还需要等待它变为可点击:

WebDriverWait wait = WebDriverWait(driver, 10);
WebElement logout = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Sign Out")));
logout.click();