VBA 个元素未在 iframe 中找到
VBA elements not found in iframe
我正在尝试在 VBA 上使用 selenium 获取数据。我想先点击一个单选框才能到达所需的页面。
以下代码导致'index outside of the bounds'错误,因为没有符合条件的元素(当我driver.FindElements(by.ID("DATAINI"))
时,它显示0)。
Dim driver As New webdriver
driver.Start "ie"
driver.get fileLocation 'At this point, the website is properly opened.
Application.Wait Now + TimeValue("00:00:20")
Dim by As New by
With driver
.SwitchToFrame .FindElementByTag("iframe")
.FindElements(by.ID("DATAINI"))(0).Click
End With
然而,当我检查代码时,有一些元素具有我指定的 ID。我该如何解决这个问题?
我想,页面不止1个iframe
,所以你肯定不能用TagName定位到合适的iframe。
你可以试试下面的 css :
driver.SwitchToFrame driver.FindElementByCss("iframe[src^='https://ptax.bcc.gov.br/ptax']")
然后您可以与 DATAINI
互动,我在上面的屏幕截图中没有看到这一点。
我正在尝试在 VBA 上使用 selenium 获取数据。我想先点击一个单选框才能到达所需的页面。
以下代码导致'index outside of the bounds'错误,因为没有符合条件的元素(当我driver.FindElements(by.ID("DATAINI"))
时,它显示0)。
Dim driver As New webdriver
driver.Start "ie"
driver.get fileLocation 'At this point, the website is properly opened.
Application.Wait Now + TimeValue("00:00:20")
Dim by As New by
With driver
.SwitchToFrame .FindElementByTag("iframe")
.FindElements(by.ID("DATAINI"))(0).Click
End With
然而,当我检查代码时,有一些元素具有我指定的 ID。我该如何解决这个问题?
我想,页面不止1个iframe
,所以你肯定不能用TagName定位到合适的iframe。
你可以试试下面的 css :
driver.SwitchToFrame driver.FindElementByCss("iframe[src^='https://ptax.bcc.gov.br/ptax']")
然后您可以与 DATAINI
互动,我在上面的屏幕截图中没有看到这一点。