0

I'm trying to enter text into an address bar using the following code in python:

driver.find_element_by_xpath('//*[@id="esri_dijit_Search_0_input"]').send_keys('text')

However, it does not register anything when running without debugging. Could you please provide any solutions on how to input text into an address bar with the following html?

<form data-dojo-attach-point="formNode">
        <input maxlength="128" autocomplete="off" type="text" tabindex="0" class="searchInput" value="" aria-haspopup="true" id="esri_dijit_Search_0_input" data-dojo-attach-point="inputNode" role="textbox" placeholder="Address or Grid Reference" title="Address or Grid Reference" style="width: 170px;">
</form>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried it but there this seems to make the 'send keys' function inoperable. – Valeriy Willetts Jul 09 '22 at 21:06
  • I'm not sure if it is a dynamic element, because all variables eg. Xpath, data-dojo-attach-point stay the same, no matter how many times I reload the page. Again there still seems to be the problem of the send_keys function at the end of the code not working - the text of the send_keys is black rather than orange from previous code I have written. – Valeriy Willetts Jul 10 '22 at 08:37

1 Answers1

1

The desired element is a dynamic element, so ideally to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.searchInput[id^='esri_dijit_Search'][title='Address or Grid Reference']"))).send_keys("text")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='searchInput' and starts-with(@id, 'esri_dijit_Search')][@title='Address or Grid Reference']"))).send_keys("text")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352