Prakash
Prakash

Reputation: 600

Selenium Webdriver is finding hidden values too

Here is the html source that I'm looking for.

<input type="hidden" value="3" id="provCount" /><input id="SettingsFrmId:settings_addProv_button" type="submit" name="SettingsFrmId:settings_addProv_button" class="inputButton" value="Add Prov" title="Add Prov" title="Add Prov" />

In the below code I'm trying to check whether the hidden element is found or not.

try:
            driver.find_element_by_id("SettingsFrmId:settings_addProv_button")
            logger[0].error('Add Prov button found.')
            return 1
except NoSuchElementException:
            logger[0].info('Add prov button is not found')`

Selenium server: 2.20.0

Here my execution fails since selenium webdriver finds the element & try block returns 1. My understanding was webdriver will not find hidden elements.

Upvotes: 1

Views: 1637

Answers (2)

EwyynTomato
EwyynTomato

Reputation: 4077

Here you have two elements

1 : An text input element with id="provCount" which is "hidden" :

<input type="hidden" value="3" id="provCount" />

2 : An button element with id="pSettingsFrmId:settings_addProv_buttonovCount" which is not "hidden" :

<input id="SettingsFrmId:settings_addProv_button" type="submit" name="SettingsFrmId:settings_addProv_button" class="inputButton" value="Add Prov" title="Add Prov" title="Add Prov" />

Then, You try finding the button element with id = "SettingsFrmId:settings_addProv_button" (which is not hidden!)

driver.find_element_by_id("SettingsFrmId:settings_addProv_button")

If you are actually trying to check on the hidden one (which is actually a text input), you should change the line above to:

driver.find_element_by_id("provCount")

Upvotes: 1

Sunilkumar V
Sunilkumar V

Reputation: 962

When i tried to read hidden text box value, it failed over there with "Element Not Found" error message. AFIK, Webdriver will not identify hidden elements. Make sure your locator Id is unique.

Upvotes: 0

Related Questions