Reputation: 553
The html code snippet as:
<thead id="addDet:cust:th" class="emp">
<tr id="addDet:cust:ch" class="emp">
<th class="emp" scope="col" id="addDet:cust:ch:j_idt484">S. No.</th>
<th class="emp" scope="col" id="addDet:cust:ch:j_idt487">Name
<font color="#FA5882">*</font></th>
I tried to fill the field as:
driver.find_element_by_id("addDet:cust:j_idt487").send_keys("XX")
But I am getting the error as:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"psdetail:j_idt490"}
Any help will be appreciable.
Upvotes: 0
Views: 257
Reputation: 4424
The xpath you've provided doesn't point to a field to input data into, in fact it's actually pointing to the column header. That's why you weren't able to input data into it.
Please try the below xpath to fill the name and age in the first row in the passenger details:
driver.find_element_by_xpath("(//tbody[@id='addPassengerForm:psdetail:tb']//input[contains(@id,'psgnName')])[1]").send_keys("ABC")
driver.find_element_by_xpath("(//tbody[@id='addPassengerForm:psdetail:tb']//input[contains(@id,'psgnAge')])[1]").send_keys("24")
Similarly for inputting data into the next row for passenger name, you just have to tweak the last part of xpath from [1]
to [2]
.
Upvotes: 1
Reputation: 473813
The id
attribute value looks very much like it is dynamically generated. In this case it is not a good idea to rely on it. Instead, use the element's text:
driver.find_element_by_xpath("//th[. = 'S. No.']")
Upvotes: 0
Reputation: 63
try using xpath contains or CSS start with //xpath "//*[contains(. , 'S. No.')]"
Upvotes: 0
Reputation: 3895
After fixing your selector (Imcphers answer/comments), is it possible that the element is NOT in the DOM at the time you're trying to find the element? Is it dynamically loaded? If so you'll probably have to use an explicit
or implicit
wait.
http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp
Try
driver.implicitly_wait(10)
after you initialize your driver
Upvotes: 0