2

I'm using Selenium Webdriver / python to walk through a site with a complicated login screen.

The internals of the login are something like this:

  1. Javascript sends the username, along with a random number to the server
  2. The server sends back a salt value, which gets combined with the password and hashed (on the client side).
  3. The hashed password is sent to server and login proceeds.

Selenium can successfully login with the following code, but ONLY if Firefox has the focus.

driver.find_element_by_id("ctl00_ContentPlaceHolder1_UserNameT").clear()
driver.find_element_by_id("ctl00_ContentPlaceHolder1_UserNameT").send_keys("username")
driver.find_element_by_id("ctl00_ContentPlaceHolder1_PasswdT").clear()
driver.find_element_by_id("ctl00_ContentPlaceHolder1_PasswdT").send_keys("pa$$word")
time.sleep(2.5)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_btnLogin").click()

When Firefox has the focus, the click() command is what causes the password to be hashed - I see the number of characters on the screen change. And this does not happen if Firefox is not focused (e.g. if I am stepping through the code in the python window).

Shouldn't Selenium be simulating browser focus? Can I get around this with Selenium? If not, can Python steal my focus back to Firefox when I get to this section of code? Unfortunately I need to walk through this login screen somewhat frequently. OS is OSX 10.9.2.

2 Answers 2

1

Firefox has problems handling events on non active windows. You could try to enable the flag focusmanager.testmode on the firefox profile. Check my answer here for more details.

0

Perhaps the driver.switch_to_window command, combined with a click() on a page element to bring focus will work?

Read more here: http://selenium-python.readthedocs.org/en/latest/navigating.html#moving-between-windows-and-frames

1
  • 1
    So this did not work, but I tried the Chrome driver and it did work. So my problem is solved, but the broader problem of why Selenium/FF behave this way is not.
    – pnj
    Apr 5, 2014 at 23:32

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.