Before calling any of the element's send_keys(), I first check if it's enabled and visible so it doesn't raise an exception.
What happens is is_Displayed returns True and when I try to send_keys to that element it still raises an exception of ElementNotVisible. Is this some form of a bug?
It works on some websites, it doesn't work on another.
def login():
elem = browser.find_elements_by_xpath('//input[contains(@name, "user")]')
for elements in elem:
if elements.is_displayed():
if elements.is_enabled():
elements.send_keys(username)
elem = browser.find_elements_by_xpath('//input[contains(@name, "pass")]')
for elements in elem:
if elements.is_displayed():
if elements.is_enabled():
elements.clear()
elements.send_keys(password + Keys.RETURN) #Crashes here
time.sleep(4)
return
the is_displayed() method returns a boolean value specifying whether the target element is displayed or not displayed on the web page. The preceding code uses the isDisplayed() method to determine if the element is displayed on a web page. The preceding code returns true for the Google Search button.
isEnabled() Method in Selenium isEnabled() method is used to check if the web element is enabled or disabled within the web page. This method returns “true” value if the specified web element is enabled on the web page otherwise returns “false” value if the web element is disabled on the web page.
Try this:
def login():
user_elements = browser.find_elements_by_xpath('//input[contains(@name, "user")]')
for user in user_elements:
if user.is_displayed():
if user.is_enabled():
user.send_keys(username)
pass_elements = browser.find_elements_by_xpath('//input[contains(@name, "pass")]')
for passw in pass_elements:
if passw.is_displayed():
if passw.is_enabled():
passw.clear()
passw.send_keys(password + Keys.RETURN) #Crashes here
time.sleep(4)
return
It's likely your choice of variable names make you clobber the outside loop with the inside loop.
If anyone is still wondering what problem was, it was caused by javascript hiding element after page was fully loaded.
Completely disabling javascript on page solved that issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With