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

Time:05-06

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" >

Any help would be greatly appreciated. Thank you.

CodePudding user response:

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'")
  • Related