python selenium send_keys wait python selenium send_keys wait selenium selenium

python selenium send_keys wait


You could try to use the following code:

query = WebDriverWait(self.browser, 5).until(            expected_conditions.presence_of_element_located((By.ID, "name")))query.send_keys('python')WebDriverWait(self.browser, 5).until(lambda browser: query.get_attribute('value') == 'python')self.browser.find_element_by_id("button").click()

This code should allow you to wait until a full string is entered in the field.


#to use send_keysfrom selenium.webdriver.common.keys import Keys     #enter a url inside quotes or any other value to sendurl = ''#initialize the input field as variable 'textField'                     textField = driver.find_element_by........("")#time to wait       n = 10#equivalent of do while loop in python                          while (True):   #infinite loop                      print("in while loop")    #clear the input field    textField.clear()                       textField.send_keys(url)    #enter the value    driver.implicitly_wait(n)    #get the text from input field after send_keys    typed = textField.get_attribute("value")        #check whether the send_keys value and text in input field are same, if same quit the loop      if(typed == url):                         print(n)      break    #if not same, continue the loop with increased waiting time    n = n+5 


If I am interpreting your question correctly, you have a web control that provides a "search" field which will progressively filter a list based on the content of the field. So, as you type "python", your list will get reduced to just the items that match "python". in this case you'll want to use your code, but add an additional wait for the item in the list that matches. something like this:

WebDriverWait(self.browser, 5).until(            expected_conditions.presence_of_element_located((By.ID, "name")))query = driver.find_element_by_id('name') query.send_keys('python')options_list = some_code_to_find_your_options_listtarget_option = WebDriverWait(options_list, 5).until(expected_conditions.presense_of_element_located((By.XPATH, "[text()[contains(.,'python')]]")))driver.find_element_by_id("button").click()

This all assumes that the button selects the chosen item.