0

Using Selenium with PhantomJS (python 2.7) I find a text box on a page (Cisco Unity 7 FYI), and try to send keys.

driver.find_element_by_id("pwdPwdPassword").send_keys("12345678")
driver.save_screenshot('screen.png')

Looking at the screen shot, only 2 keys are actually sent. Not sure which ones as Unity masks the password. I notice that if I walk through my script in IDLE and slowly enter

driver.find_element_by_id("pwdPwdPassword").send_keys("1")
driver.find_element_by_id("pwdPwdPassword").send_keys("2")
driver.find_element_by_id("pwdPwdPassword").send_keys("3")
driver.find_element_by_id("pwdPwdPassword").send_keys("4")
....

The keystrokes actually make it into the text box. I tried putting a time.sleep(2) between each send_keys in my script but the results are the same. I am hoping there is a trick to this so I don't have to add 30 seconds to my script just to enter this password!

Thanks!!!

6
  • What version of webdriver are you using? What browser are you using? Is the same behavior present for different pages or browsers? If this case depends on application only, my only suggestion is to make your own 'tricky' send keys method. For example def send_keys( element, keys_to_send): for key in keys_to_send: element.send_keys(key) (Of course, element should be defined first) Commented Nov 13, 2013 at 23:53
  • Sorry! WebDriver 2.37.2, PhantomJS 1.9.2. I have tested this with Chrome and it works so I guess its a PhantomJS issue. I need a headless browser, do you know if its possible with Chrome? Thanks Commented Nov 14, 2013 at 13:30
  • On Ubuntu I'm using pyvirtualdisplay lib. It's actually Chromedriver on virtual display in my case Commented Nov 14, 2013 at 13:48
  • This will be run on Windows boxes, i could setup xming or a remote xserver to send the display to but I am hoping I can do this without that. It appears phantomjs is the only browser i can run without a gui locally. Commented Nov 14, 2013 at 15:28
  • too bad. So, use my tricky nethod or smth like it. Or you can paste values via js. Thousands of worarounds :) Commented Nov 14, 2013 at 16:01

2 Answers 2

1

As an option, try to use jQuery:

def enter_password(driver, password):
    driver.execute_script("""$("#pwdPwdPassword").val('%s');"""" % password) 
    ## id must be unique per page
Sign up to request clarification or add additional context in comments.

2 Comments

I gave you an upvote but I cant accept the answer as it did not work for me. To solve my problem I ended up doing some tab magic. I found the element before the text box giving me a problem and sent that element a Keys.TAB. Basically trying to find the element before it and tabbing to it like on a irl keyboard. Then send_keys was working. Why I had to tab to it, dont know but it works so I am happy :)
In this case you may also try clicking on it before sending keys.
0

Maybe you should store the input field object like this:

input_field = find_element_by_id("pwdPwdPassword")
input_field.send_keys("12345678")

Also try to update your PhantomJs webdriver if this doesn't work

Comments

Your Answer

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.