Reputation: 49
Follwing is the HTML code:
<div class="search-nav">
<div class="field">
<input id="search" type="text" class="input-data"
placeholder="Enter Claim or Payment Number..."
name="QuickSearch">
</input>
</div>
<button class="search-button" data-ng-click="performSearch($event)">
<i class="search icon"></i></button>
</div>
Python selenium code:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='field' and @id='search']"))).send_keys("12343545")
Upvotes: 0
Views: 83
Reputation: 1
Currently your Xpath is referring to nothing as there is no such Web Element with id and class you are referring to.
'AND' can only be used in xpath on two attributes present in same tag. Eg: //input[@id='search' AND name='QuickSearch']
So, Update your xpath as:
//input[@id='search'] OR //input[@id='search' AND @name='QuickSearch']
Upvotes: 0
Reputation: 29362
If the input field is in iframe then you have to switch control of webdriver to that particular iframe for performing any operations inside it :
Code
driver.switch_to.frame(driver.find_element_by_id("payspan-health"))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'search')))
driver.find_element_by_id('search').send_keys("12343545")
#To switch back to the main window, you can use
driver.switch_to.default_content()
Upvotes: 0
Reputation: 4739
I thinks there is a frame
there, you first swithc to frame then locate element
//Switch to frame
driver.switch_to.frame(driver.find_element_by_id("Id of your Frame"))
waitElem = WebDriverWait(driver, 10)
element = waitElem .until(EC.element_to_be_clickable((By.ID, 'search')))
element.send_keys("323232")
Please place your frame locator in place of "Id of your Frame"
Upvotes: 1
Reputation: 1939
The reason why you cannot pass text is because you are looking for an element where class = 'field'
and id = 'search'
. With this, you are referring to 2 different element. class = 'field'
is a <div>
and and id = 'search'
is an <input>
What you want to do is, send text to the input only. Now if you want to send it to this specific input under the div with class = 'field'
try the following:
//div[@class='field']/input[@id='search']"))).send_keys("12343545")
Or if this is the only input field with id "search".
//input[@id='search' and @class='input-data']
Upvotes: 0