[英]Pop up box - how to handle it in selenium
我遇到了同樣的問題,並通過使用XPATH搜索框架解決了該問題。 也許這段代碼可以幫助您:
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();
您尚未提供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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.