1

I have written the following.

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys
bot = webdriver.Firefox()
bot.find_element_by_name("username").send_keys(config['username'])

When I am using send_keys and happen to be typing at the same instant, then what I typed is also added in the username.
How to avoid this?

Example:

I want to fill the username with "sandeep" If at the same instant I press 'a', then the username becomes "sandeepa" or something equivalent.

3
  • 3
    I doubt that there would be a simple solution for that. Do you have to type when this script runs? Commented Aug 18, 2016 at 14:01
  • This seems more like a limitation of the OS/Browser and Selenium than an actual issue. As DeepSpace added, do you need to type at the same time as the test is running? Commented Aug 18, 2016 at 14:21
  • I used it to download and sync some files so it would be running at the back and I am using a cron job to run it so the simple solution is not used. Commented Aug 18, 2016 at 21:00

2 Answers 2

1

You can use executeScript method:

webdriver.execute_script("document.getElementById('username').setAttribute('value', 'Sandeep')")

JavaScript will do text insertion as single operation.

Sign up to request clarification or add additional context in comments.

Comments

0

I see 2 options:

  1. Create hidden input send keys to it than perform copy/paste from hidden to visible input, after remove hidden input.

  2. Hide input, than send_keys to it and after show it back.

Usefull links:

Performing a copy and paste with Selenium 2

WebDriver: add new element

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.