0

I need to find the input box in this HTML:

<div id="employeesDataTable_filter" class="dataTables_filter">
<label>
<input type="search" class="form-control input-sm"
placeholder="Filter..." aria-controls="employeesDataTable">
</label>
</div>

But for the life of me cannot - please help,

I have successfully written bags of tests and found many page element of different types but this one has stumped me.

I am very new to this and have tried

By ExecutiveSearchBox = By.XPath("//input[@type='search' and 
    class='dataTables_filter']");
DebanjanB
  • 118,661
  • 30
  • 168
  • 217

2 Answers2

0

You have encountered problems because you are selecting class attribute on input node instead on div. Try following selector:

//div[@class='dataTables_filter']//input[@type='search']

Also as @Marco Forberg mention it is good to use contain() XPath function in case if there are multiple classes provided for element:

//div[contains(@class, 'dataTables_filter')]//input[@type='search']

I hope it'll help to resolve your issue :)

Gucu112
  • 511
  • 4
  • 7
0

To find the input element in your html snippet, you simply use

FindElement( By.CssSelector( "input" ) )

But note:

  • not always is the input box editable after page load is completed, it may take some time. It might be wise to wait until the box becomes editable if you want to send data to it.
  • not always does the input box appear immediately in the DOM. With modern UI like Angular, it might be not there immediately, might be something else for a while and only later become an input field and the like. Also here, making use of Seleniums wait functionality sure is a good idea.

I ALWAYS wait for the DOM state I expect and only after some time when the state is not achieved I throw.