I am trying to log into a website with Selenium in Python. My code is below. I am able to sucessfully find (by_xpath) the username field and print its attributes. However, I am unable to send_keys to it or interact with it in any way. Further, I am unable to even select the password field, even though various xpath utilities tell me I am using the right address for the field.
I would like to input my username, password and click submit.
from selenium import webdriver
from selenium.webdriver.common import action_chains, keys
import time
driver = webdriver.Firefox()
driver.get("http://games.espn.go.com/ffl/signin?redir=http%3A%2F%2Fgames.espn.go.com%2Fffl%2Fleaguerosters%3FleagueId%3D1111554")
time.sleep(10)
driver.find_element_by_xpath("//input[@type='text']").send_keys("JimH")
driver.find_element_by_xpath("//input[@type='password']").clear()
driver.find_element_by_xpath("//input[@type='password']").send_keys("N0tMyR3@1P@55w0rd")
driver.find_element_by_xpath("//button[@type='submit']").click()
You can see in my code that the site that I am trying to access is this .
I have searched this forum extensively for a solution:
The exception that I receive from my code above is pasted here:
/usr/bin/python2.7 /home/ff/PycharmProjects/Test/Test_action_chain.py
Traceback (most recent call last):
File "/home/ff/PycharmProjects/Test/Test_action_chain.py", line 8, in <module>
driver.find_element_by_xpath("//input[@type='text']").send_keys("JimH")
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 328, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 454, in _execute
return self._parent.execute(command, params)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmpOFHnLq/extensions/fxdriver@googlecode.com/components/command-processor.js:9981)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpOFHnLq/extensions/fxdriver@googlecode.com/components/command-processor.js:12517)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpOFHnLq/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpOFHnLq/extensions/fxdriver@googlecode.com/components/command-processor.js:12539)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpOFHnLq/extensions/fxdriver@googlecode.com/components/command-processor.js:12481)
The form which you are trying to fill is within an iframe
. To make selenium work in an iframe
you need to switch to the specific frame you wish to work in using switch_to_frame()
function. The syntax which you mentioned is incorrect. Try the code given below.
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get(link)
driver.switch_to.frame(driver.find_element_by_id("disneyid-iframe"))
driver.find_element_by_xpath("//input[@type='text']").send_keys("JimH")
...
When you want to get out of the frame, use this:
driver.switchTo().defaultContent();
TIP: Use waits instead of time.sleep(10)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.