selenium - 无法为附加组件文本找到带有 xpath 的元素(正确的 xpath)
问题描述
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get("http://www.spicejet.com");
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//a[contains(text(),'Add-Ons')]")))
.build().perform();
Thread.sleep(3000);
driver.findElement(By.linkText("Hot Meals ")).click();
driver.close();
无法使用 xpath 定位元素 //a[contains(text(),'Add-Ons')
它与框架有关吗?
解决方案
当我手动验证时,您的 xpath 可以找到正确的元素。我怀疑页面没有完全加载,请在调试sleep
后添加一些。dirver.get()
driver.get("http://www.spicejet.com");
Thread.sleep(10*1000) // sleep 10 seconds to wait page open completely.
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//a[contains(text(),'Add-Ons')]")))
.build().perform();
推荐阅读
- android - java.io.fileNotFoundException(权限被拒绝)
- java - onConfigurationChanged 无法正常工作
- javascript - 在 div 中显示 json html 数据
- webpack - Webpack DefinePlugin 支持变量还是只支持常量?
- python - 如何附加到包含时间序列的 DataFrame 中的列
- python - 在模块导入时,打印出有用的语句
- select - 在 SQL Server 中根据列值选择记录
- javascript - 除日期外,如何在数字和非数字之间添加空格?
- protractor - protractor + cucumber 等待和超时而不执行完整测试
- php - 多个表的多个列连接到同一个表