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']");
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 :)
To find the input element in your html snippet, you simply use
FindElement( By.CssSelector( "input" ) )
But note:
I ALWAYS wait for the DOM state I expect and only after some time when the state is not achieved I throw.
To locate and send a character sequence within the desired element you have induce WebDriverWait for the desired ElementToBeClickable and you can use either of the following Locator Strategies as solutions:
CssSelector
:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.form-control.input-sm[aria-controls='employeesDataTable']"))).SendKeys("John Hyslop");
XPath
:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='form-control input-sm' and @aria-controls='employeesDataTable']"))).SendKeys("John Hyslop");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.