如何使用 selenium vba 切换 iframe? [英] How can I switch iframe using selenium vba?
问题描述
使用 selenium 在 vba 中编写脚本以在运行时切换 iframe,出现错误:对象不支持此属性.如果我考虑下面的例子,我该怎么做.
Writing a script in vba using selenium for the purpose of switching iframe when I run it, I get an error: object doesn't support this property. How can I do it if I take the below example as consideration.
Sub HCAD()
Dim driver As New ChromeDriver
driver.Get "http://hcad.org/quick-search/"
driver.Wait 500
driver.SwitchToFrame (driver.FindElementByTag("iframe"))
End Sub
这是我试图从目标页面获取地址名称的脚本.结果当我到达那里时,我遇到了另一个 iframe,所以最终什么也没得到.我在脚本中提到的地址只有一个名字.
Here is the script with which i was trying to get the name of the address from the target page. Turn out when i reach there i faced another iframe so end up getting nothing. There is only one name against the address i mentioned in my script.
Sub HCAD()
Dim driver As New ChromeDriver
Dim post As Object
driver.Get "https://public.hcad.org/records/quicksearch.asp"
driver.Wait 500
driver.FindElementById("s_addr").Click
driver.FindElementByName("stnum").SendKeys ("8227")
driver.FindElementByName("stname").SendKeys ("FINDLAY ST")
driver.FindElementByXPath("//input[@value='Search']").Click
driver.Wait 1000
Cells(1, 1) = driver.FindElementByXPath("/html/body/table/tbody/tr/td/table[5]/tbody/tr[2]/td[1]/table/tbody/tr/th").Text
End Sub
推荐答案
根据@Mathieu Guindon 的建议,解决方案应该如下(工作中的一个).
According to the suggestion given by @Mathieu Guindon, the solution should be like below (working one).
Sub HandleIframe()
With New ChromeDriver
.get "http://hcad.org/quick-search/"
.SwitchToFrame .FindElementByTag("iframe", timeout:=10000)
.FindElementById("acct").SendKeys "8227"
.FindElementByCss("input[value='Search']").Click
End With
End Sub
这篇关于如何使用 selenium vba 切换 iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!