How can I switch iframe using selenium vba?

前端 未结 2 1003
故里飘歌
故里飘歌 2021-01-27 18:43

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 be

相关标签:
2条回答
  • 2021-01-27 19:29

    little extra good functionality added to your code

    btw .. the cells(1,1) line fails

    Sub HCAD()
    
        ' add ref: Selenium Type Library
    
        Dim driver As New ChromeDriver    ' PhantomJSDriver (this one is for "headless" browsing) 
    
        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
    
        Dim bbb As Object
        Set bbb = driver.TakeScreenshot
        bbb.ToExcel Cells(5, 1)
        Set bbb = Nothing
    
    
        Cells(1, 1) = driver.FindElementByXPath("/html/body/table/tbody/tr/td/table[5]/tbody/tr[2]/td[1]/table/tbody/tr/th").Text
    
        Set driver = Nothing
    
    End Sub
    
    0 讨论(0)
  • 2021-01-27 19:36

    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
    
    0 讨论(0)
提交回复
热议问题