4

I saw plenty of questions / answer on this ElementNotVisibleException issue with selenium. The best code I have done so far is the following :

from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "http://www.cfnews.net/user/login"
driver.get(url)
print "Got url."
wait = WebDriverWait(driver, 10)
login_form = wait.until(EC.invisibility_of_element_located((By.ID, "user-login")), "pbm")
print "Element located."
displayed = login_form.is_displayed()
print "login_form.is_displayed() = ", displayed
login_form.send_keys("a")

which give the following output :

Got url.
Element located.
login_form.is_displayed() = False
---------------------------------------------------------------------------
ElementNotVisibleException Traceback (most recent call last)
<ipython-input-110-d45e06b37320> in <module>()
 12 displayed = login_form.is_displayed()
 13 print "login_form.is_displayed() = ", displayed
---> 14 login_form.send_keys("a")
/Users/romain/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.pyc in send_keys(self, *value)
 345 value = self._upload(local_file)
 346 
--> 347 self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
 348 
 349 # RenderedWebElement Items
/Users/romain/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.pyc in _execute(self, command, params)
 492 params = {}
 493 params['id'] = self._id
--> 494 return self._parent.execute(command, params)
 495 
 496 def find_element(self, by=By.ID, value=None):
/Users/romain/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in execute(self, driver_command, params)
 234 response = self.command_executor.execute(driver_command, params)
 235 if response:
--> 236 self.error_handler.check_response(response)
 237 response['value'] = self._unwrap_value(
 238 response.get('value', None))
/Users/romain/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.pyc in check_response(self, response)
 190 elif exception_class == UnexpectedAlertPresentException and 'alert' in value:
 191 raise exception_class(message, screen, stacktrace, value['alert'].get('text'))
--> 192 raise exception_class(message, screen, stacktrace)
 193 
 194 def _value_or_default(self, obj, key, default):
ElementNotVisibleException: Message: element not visible
 (Session info: chrome=54.0.2840.98)
 (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.0 x86_64)

So, the page is downloaded, the html is got by the driver, but it is not possible to send any key. There is also the answer here : Selenium Element not visible exception

Which proposes to use ActionChain, but I tried without success :(

If I do :

driver.page_source

I got the html :

u'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/"><head>\n \n \n<title>Ouverture de session / Utilisateur - l\'actualit\xe9 du capital investissement : transactions LBO, M&amp;A, Venture France - Corporate Finance et Private Equity</title>\n<meta name="description" content="CFNEWS est le premier site \xe0 proposer actualit\xe9s et r\xe9f\xe9rentiels du corporate finance en France sur les...etc...
asked Nov 19, 2016 at 22:48

2 Answers 2

2

Try this and sucess!!!

from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
url = "http://www.cfnews.net/user/login"
driver.get(url)
wait = WebDriverWait(driver, 10)
login_form = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input#nom-user")))
login_form.send_keys("a")
answered Jan 14, 2017 at 19:51
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of ".invisibility_of_element_located" you can try "visibility_of_element_located".

answered Nov 30, 2016 at 14:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.