0

send_keys() method of selenium python not working sometimes. Keys that I send and the the ones that selected are different sometimes. This usually happens when it takes too long for the page to load.

I Tried using sleep before sending the keys for the element to load all the drop down values but this too doesn't work.

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "Tag")))
sleep(10)
self.driver.find_element_by_id('Tag').send_keys('Key Value')
1
  • Which web driver (including version) and browser (including version) are you using? Commented Sep 18, 2019 at 22:27

2 Answers 2

2

As you intend to use WebDriverWait before invoking send_keys() instead of expected_conditions as visibility_of_element_located() you need to use element_to_be_clickable() as follows:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "Tag"))).send_keys("Key Value")
Sign up to request clarification or add additional context in comments.

2 Comments

@DebanjanB Thank you very much
Still the problem of different key getting selected persists. Is there any other workaround to fix this
0

The below code helps in getting the particular option getting selected,

    select2=WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.ID, "ID_Name")))
    for item2 in select2.find_elements_by_tag_name('option'):
        if item2.text.strip() == 'Option Name':
            item2.click()
            break

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.