-2

here's the code of the textbox :

<form>
    <input autocomplete="off" id="number" name="number" type="tel" aria-describedby="error-for-number tooltip-for-number" data-current-field="number" data-fillr-id="424069765" data-fillr="bound" style="padding: 8px 10px; font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, &quot;San Francisco&quot;, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, sans-serif;">
</form>

By the way it did't work when I tried to access it by id or name like this :

browser.find_element_by_id('number')
browser.find_element_by_name('number')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 2
    If you don't want to know the type of the element then how are you going to decide whether it is a button or text-box? – S Ahmed Apr 26 '19 at 20:00
  • you should do a common mapping with a selector that gets both of these elements, then try a element.Clear() to check if its an input (textbox), if it is not, an exception will be returned. You can catch that exception and click the element instead,and if clear does not throw an exception, just type the text you want. – Valga Apr 26 '19 at 20:08
  • what error does it show when you try to find it by id? – S Ahmed Apr 27 '19 at 03:48

1 Answers1

0

To locate the TextBox you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#number[name='number'][type='tel']")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='number' and @name='number'][@type='tel']")))
    
  • 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