Deyan Georgiev Deyan Georgiev - 1 year ago 95
Python Question

Selenium fails to select element by id

Here is the HTML code of the element:

<input maxlength="64" name="pskSecret" class="text" id="pskSecret" value="" size="32" type="text">

And here is my python code, which tries to select it:

self.driver.find_element_by_id("pskSecret").send_keys(data) # data is variable

However I got exception, stating that selenium is unable to locate the element.
Any ideas what may be causing the problem

Edit: Also the element is inside an iframe, however I'm accessing other elements in it which are working correctly.

Answer Source

May be when you are going to find element, it could not be load on the DOM due to timing issues. You should try using WebDriverWait to wait until element is visible as below :-

from import By
from import WebDriverWait
from import expected_conditions as EC

wait = WebDriverWait(self.driver, 10)

input = wait.until(EC.visibility_of_element_located((By.ID, "pskSecret")))

Note :- if this element is inside any frame you need to switch that frame before finding element using self.driver.switch_to_frame("your frame id or name")

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download