Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can you input text into an input element without using send keys in Python Selenium?

I’m working with a website where send_keys sometimes works and sometimes doesn’t (I have no idea why). Sometimes it sends keys then I try a few hours later and it doesn’t work anymore. I was wondering if anyone knew a way to send text/numbers into a input element WITHOUT using send_keys.

For example, would it be possible to input text into the following element without using send_keys:

<input _ngcontent-coh-c546="" type="text" name="tag" maxlength="25" placeholder="Tags" class="ng-dirty ng-valid ng-touched">

Any help would be greatly appreciated. Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This should work effectively and faster compared to send_key

from selenium import webdriver

driver = webdriver.Chrome('chromedriver')
driver.get("http://www.google.com");
driver.execute_script("document.getElementsByName('q')[0].value='What ever you want to be typed here'")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading