0

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

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
SIM
  • 21,997
  • 5
  • 37
  • 109
  • why don't you just go here? https://public.hcad.org/records/quicksearch.asp – jsotola Aug 08 '17 at 05:34
  • No way. If i ignore the first iframe. There are others in the target page. I would like to know if there is any option in vba to switch the iframe – SIM Aug 08 '17 at 05:37
  • 1
    I'd start with removing these extraneous parentheses around the return value of `FindElementByTag`, which looks very very much like it's returning an object reference - which is a very very bad idea to pass `ByVal` like you're doing with these parentheses. – Mathieu Guindon Aug 08 '17 at 05:54
  • @Shahin, when you post a question on SO, please include **all** information, like, the code line that causes the fault. all you have done is, said that you have an error, but you did not say where the error occurs. your program is simple, so it was easy to **guess** where the error was occurring. if your program was more complicated, i doubt that anyone would bother to help you until you provided the information. – jsotola Aug 08 '17 at 06:01
  • Sorry jsotola for my delayed response. I caught a power outage. – SIM Aug 08 '17 at 06:32
  • I'm gonna update my post with a little more information to let you know why i'm after iframe. Btw, don't get me wrong if i hurt your feeling unintentionally. – SIM Aug 08 '17 at 06:33
  • @Shahin, you did not hurt my feelings. i was just trying to get more information from you by making you think about the information that you provided. removed my two comments :) – jsotola Aug 08 '17 at 07:27

2 Answers2

0

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
jsotola
  • 2,238
  • 1
  • 10
  • 22
0

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
SIM
  • 21,997
  • 5
  • 37
  • 109