1

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:

  • This didn't help because I wasn't sure how to send keys, all this idd was click. Also it didn't provide descriptive error messages: Selenium Element not visible exception
  • When I tried this one I got an exception that the box I was trying to select was outside the scroll window, which was not true: Unable to select radio button with selenium in Python
  • Another post told me to select an frame which i was unable to do. (select_frame("disneyid-iframe") errored out on me)

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/[email protected]/components/command-processor.js:9981)
    at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpOFHnLq/extensions/[email protected]/components/command-processor.js:12517)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpOFHnLq/extensions/[email protected]/components/command-processor.js:12534)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpOFHnLq/extensions/[email protected]/components/command-processor.js:12539)
    at DelayedCommand.prototype.execute/< (file:///tmp/tmpOFHnLq/extensions/[email protected]/components/command-processor.js:12481)

1 Answer 1

0

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).

2
  • Jason, your suggestion worked! Thank you for your prompt and thorough response! Can you explain briefly how I would know that the elements that I was looking for were on a different frame?
    – JimH
    Oct 26, 2015 at 12:25
  • Use the developer console of the browser to see the element tree of the HTML page. For Chrome, you can follow this link. For Firefox, follow this link. Oct 26, 2015 at 12:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.