Selenium Webdriver:等待超时例外的后备?
我目前正在使用Selenium Webdriver(通过Node.js运行)来刮擦几十年来分散的一堆天气数据(因为该网站在我期望的完整分辨率下仅加载一天的每个页面价值!)。因此,该过程不可或缺的一部分涉及在URL之间跳跃,等待适当的数据表(如果适用)加载每个相应日期的页面。
虽然我当前的方法适用于绝大多数页面,但使用明确的等待方法等待驱动程序。没有可用的数据(网站完全省略了表元素),因此也触发了我的刮板上的超时错误(由于不存在的表显然找不到!),不幸的是,这也使我的整个程序停止了。
但是,我认为但是,硒的等待方法中必须内置一些相当标准的后备,使您可以运行替代代码(或者简单地进入测试的其余部分 - 也许有一些日志),以防预期条件在指定后无法实现等待时间?
我最初的想法是通过连接。 URL)但是,如果“继续”操作在循环中嵌套在功能中,则“继续”操作似乎无效。
I'm currently using Selenium WebDriver (ran through node.js) to scrape a bunch of weather data dispersed over several decades (since the site only loads one day's worth of data per page at my desired full resolution!). An integral part of the process thus involves jumping between URLs, waiting for the appropriate data table (if applicable) to load for the page of each corresponding date.
While my current approach works for the vast majority of pages, using the explicit waiting method await driver.wait( until.elementsLocated( By.css( #myDataTableOfInterest)), 10000)
, there are occasional periods with no available data (where the website omits the table element altogether), thus also triggering a TimeOut error on my scraper (since the non-existent table obviously can't be found!) that unfortunately also halts my entire program.
I assume however there must be some fairly standard fallback built into Selenium's waiting methods that lets you run alternative code (or simply move on to the rest of the test - perhaps with some log) in case an expected condition doesn't materialize after the specified waiting time?
My original thought was to bypass it by attaching .then(<some empty/log function>,error => {continue})
(since this code is happening in a loop that iteratively updates the day URL) but it appears that the "continue" operation isn't valid if it's nested inside a function within the loop..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试捕获错误并执行要处理的任何事情。
You can try catching the error and doing what ever you want to handle it.