0

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

1
  • better create minimal working code with real URL so we could run it and see this problem Commented Aug 25, 2020 at 13:09

2 Answers 2

1

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")
Sign up to request clarification or add additional context in comments.

Comments

0

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')");

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.