selenium - Selenium highlight working only on one specific machine
问题描述
Selenium code to highlight an element is working only on one of the system. I have updated chrome and chrome driver on both of them but in one machine, it works but code breaks on another machine when trying to highlight the page element. Below is the exception:
An error occurred while fetching element : Expected condition failed: waiting for visibility of element located by By.id: body_x_grid_x__ctl2__ctl0 (tried for 15 second(s) with 500 MILLISECONDS interval)
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: '**', ip: '**', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab), userDataDir=**}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=67.0.3396.99, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: 9854688adcdbe56519b9869c496b58e2
at com.selenium.element.action.Wait.elementAction(Wait.java:68)
....
It does not find the element within specific periods and breaks.
解决方案
将您的代码包装在try
/catch
子句中,并在其中catch
保存webdriver.getPageSource()
. 然后检查它的内容(如果你用扩展名命名文件,你甚至可以在浏览器中打开它.html
)并查看一个元素是否id='body_x_grid_x__ctl2__ctl0'
实际存在。
我不确定,但看起来这个 id 是由应用程序自动生成的,并且在另一台机器上生成的方式可能有所不同。
推荐阅读
- java - 如何在 Google-App 上允许快速发布请求?
- logstash - 将日志从 filebeat 发送到 logstash 错误:无法发布事件,原因是:lumberjack 协议错误
- excel - 使用 Excel 测试范围
- java - List.equals() 是否在覆盖 java.lang.Object.equals() 时执行了预期的行为?
- python - Mongoengine烧瓶获取dbstats
- java - 如何将 Java/Kotlin 转换为 CLI?
- ios - 从IOS上的通知操作按钮打开一个特定的应用程序?
- sql - 不同的列选择并按多列分组
- java - 填充队列
- javascript - 如何使用 iFrame 完全导入网站源代码