Which webpage element is the proper one for Findelementby?

61 Views Asked by At

HTML elements from Inspect Redfin.com

The highlighted code references the red search button with the magnifying glass to the right of the search box. I don't know which element to refer to it with Selenium webdriver FindBy. Can someone tell me the correct FindElementby and which element? Thanks!

There is no name and ID to refer to it.

2

There are 2 best solutions below

4
gords On

The css selector is button[type='submit'][tabindex='0'] > svg

1
MT1 On

This works for me ...

Option Explicit

Sub Test()
    Dim chr As ChromeDriver
    Dim mykeyword As String
    Set chr = New Selenium.ChromeDriver
    Call chr.Start("edge")
    chr.Get ("https://www.redfin.com")
    mykeyword = Sheet1.Cells(2, 1).Value
    chr.FindElementByName("searchInputBox").SendKeys mykeyword
    chr.Wait 1000
    chr.FindElementByCss("button[type='submit'][tabindex='0'] > svg").Click
    chr.Wait 10000
    chr.Quit
End Sub