如何使用selenium vba切换iframe? [英] How can I switch iframe using selenium vba?
问题描述
使用selenium在vba中编写脚本以便在运行时切换iframe,我收到错误:object不支持此属性。如果我将以下示例作为考虑因素,我该怎么做呢。
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屋!