【问题标题】:VBA with selenium throws element not visible error带有硒的 VBA 抛出元素不可见错误
【发布时间】:2017-07-09 22:17:28
【问题描述】:

在运行我的脚本时,我遇到了带有硒的 vba 中的元素不可见错误。这是我尝试使用的代码:

Sub Table_stuff()

Dim driver As New WebDriver

With driver
    .Start "chrome", "http://apps.tga.gov.au/Prod/devices"
    .get "/daen-entry.aspx"
    .Timeouts.PageLoad = 20000
    .FindElementById("disclaimer-accept").Click
    .Timeouts.PageLoad = 20000
    .FindElementById("medicine-name").SendKeys ("pump") ''Error thrown here
    .FindElementById("medicines-header-text").Click
    .FindElementById("submit-button").Click
    .Timeouts.PageLoad = 20000
End With
End Sub

这是到达我的刮板引发特定错误的元素:

<input type="text" name="medicine-name" id="medicine-name" value="" 
placeholder="Type at least 3 characters" title="Enter medical device name" 
autocomplete="off" maxlength="100" class="placeholder" style="color: rgb(0, 0, 0);">

【问题讨论】:

  • 该元素在浏览器中是否真正可见?
  • 是的,元素在浏览器中可见。

标签: vba selenium selenium-webdriver web-scraping


【解决方案1】:

据我了解,Timeouts.PageLoad 调用实际上不会触发 selenium 驱动程序等待 - 我认为它只是设置了页面加载超时。这意味着您的代码会在打开许可证对话框时尝试将密钥发送到搜索输入 - 这会触发“元素不可见”错误。

您需要的是一个Wait 调用(最好是显式等待,但我不确定VBA 绑定是否具有该功能):

.Wait 3000  ''3 seconds

【讨论】:

    猜你喜欢
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多