【发布时间】:2017-03-19 03:16:49
【问题描述】:
我正在编写一个 Selenium Webdriver 脚本,它应该点击一个链接,然后弹出这个模态窗口。
当我尝试访问卡号字段 (//input[@id=pan]) 时,我得到 No such element found exception org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"pan"}
这是我没有运气尝试过的代码:
WebElement modal = driver.findElement(By.xpath("//div[@class='ute-pay-now-modalContent']"));
driver.switchTo().frame(modal);
WebElement el = driver.findElement(By.xpath("//input[@id='pan']"));
也试过这个:
WebElement modal = driver.findElement(By.className("ute-pay-now-modalContent"));
driver.switchTo().frame(modal);
WebElement el = driver.findElement(By.xpath("//input[@id='pan']"));
也试过这个:
WebDriverWait block = new WebDriverWait(driver,10);
WebElement modal = block.until(ExpectedConditions.visibilityOfElementLocated(By.className("ute-pay-now-modalContent")));
WebElement pan;
pan = modal.findElement(By.id("pan"));
也试过这个:
driver.switchTo().defaultContent();
也试过这个:
driver.switchTo().activeElement();
有人可以帮我建议如何解决这个问题吗?
【问题讨论】:
-
您已经定义了
modal变量,但试图切换到model("modEl" != "modAl")。还要注意div和ute-pay-now-modalContent类名不是iframe,所以你不应该使用switchTo().frame()。如果可能,分享页面URL -
@Andersson:我已经纠正了错字。如果我不能使用 Frame 因为它是 Modal,那么我如何从 Modal 获取输入字段?我还没有运气。这是一个非常常见的场景,Selenium 可能已经以某种我无法找到的方式处理。
-
你能分享页面
URL吗? -
@Andersson:不知道这会有什么帮助,因为我正在谈论的页面是安全的并且需要登录(无法共享我的凭据)。但是给你:rogers.com/web/totes/#/signin
-
与
modal = block.until(ExpectedConditions.visibilityOfElementLocated(By.className("ute-pay-now-modalContent"))); modal.findElement(By.id("pan"));共享异常
标签: selenium selenium-webdriver modal-dialog