我正在用Selenium Chrome WebDriver最新版本构建一个小型自动测试脚本,但是现在我面临一个问题,即使在切换到iFrame时也尝试获取WebElement。Selenium - 在iFrame中获取WebElement时出错
这是HTML的构建方式:
你可以检查一下,还有另外一个页面“镶嵌”里面的iFrame,并且按钮的定义如下(这是我选择的一部分):
这是我使用来获取WebElement的方式(显然不及格):
WebElement frameAperturar =
driver.findElement(By.xpath("//iframe[@title='Aperturar']"));
driver.switchTo().frame(frameAperturar);
asociarSiniestroButton = driver.findElement(By.xpath("//button[@aria-label='Asociar Siniestro']"));
asociarSiniestroButton.click();
这是我当我试图让WebElement异常:
no such element: Unable to locate element: {"method":"xpath","selector":"//button[@aria-label='Asociar Siniestro']"}
(会话信息:铬= 60.0.3112.113)
你知道我怎么能得到的元素在切换到框架后,iFrame内的页面?
什么是你得到 – SaiPawan
这个错误是我得到了异常:“没有这样的元素:找不到元素:{”方法“:”的XPath“” (会话信息:chrome = 60.0.3112.113) (驱动程序信息:chromedriver = 2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform = Windows NT 6.1(选择器“:”//按钮[@ aria-label ='Asociar Siniestro']“} (警告:服务器没有提供任何堆栈跟踪信息)“ –
已更新my anwer –