saeed tq
saeed tq

Reputation: 13

how to fill javascript text box with selenium and python (without send_keys)

I want to enter a value into a field

I find the element by:

driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]')

And I do this to display the text and click:

driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').click()
driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').text

So far so good, but I use this code when I want to send a value to this field:

driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').send_keys('test')

Nothing happens and the field value does not change

Upvotes: 0

Views: 630

Answers (2)

Noob
Noob

Reputation: 41

Try to use javascriptexecutor instead of sendkeys

WebDriver driver = new ChromeDriver();
JavascriptExecutor je = (JavascriptExecutor)driver;
je.executeScript("document.getElementById('IDofElement').setAttribute('value', 'your value here')");

Upvotes: 0

Jaspreet Kaur
Jaspreet Kaur

Reputation: 127

Since we are unaware about the nature of the text box you are trying to access, there are some possibilities because of which you are facing this situation. The send_keys() works on all the text box which ever you use. Look for the points below and try applying it on the element:

  1. The element is not extracted properly, try some other locator like id, name, css_selector.
  2. The element is not ready to use, put some explicit wait and check for presence and visibility of element.

A sample code can be using explicit wait:

wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_all_elements_located(("xpath", "//*[@id='cell--gE-Ez1qtyIA']")))
element.send_keys("test")

Upvotes: 1

Related Questions