0
votes

Below is the element after typing "Abernathy and Sons" text in text field to generate auto-populated list

<div class="col-md-10 col-sm-10"> ==$0
    "Abernathy and Sons "
    <p>
        <i class="fa fa-map-maker"></i>
            " atlanta, GA"
    </p>

I have tried with the element

{browser.div(text: "Abernathy and Sons ")}

Giving error:

timed out after 30 seconds, waiting for #/"Abernathy and Sons "/, :tag_name=>"div"}> to be located (Watir::Exception::UnknownObjectException)

1

1 Answers

0
votes

The problem here is,

b.div(text: "someText") 

Will form the xpath as follows in selenium

driver.find_element(xpath: "//div[normalize-space(.)='someText']")

So normalize-space() method in xpath will compare the string after removing the trailing and leading space. So if you add a space after or before the string then it will throw the error unable to find element. So If I write the blow code then you will have the same error you are getting.

b.div(text: "someText ") #look at the space after someText.

So remove the space before and after the string it will work perfectly.