2

HTML:

<input id="4432e17d-eed6-4620-9bb4-d75ffbd321fa" type="email" placeholder="Email address" value="" name="emailAddress" data-componentname="emailAddress" autocomplete="email" autocorrect="off" autocapitalize="off" spellcheck="false">

Refreshed:

<input id="4a463943-7f58-42ea-9317-ba9f9518811e" type="email" placeholder="Email address" value="" name="emailAddress" data-componentname="emailAddress" autocomplete="email" autocorrect="off" autocapitalize="off" spellcheck="false">

How can I select this element without using ID.

I've tried by XPATH and CSS SELECTOR both haven't worked. Full XPATH:

/html/body/div[2]/div[3]/div[5]/form/div[1]/input

XPATH:

//*[@id="4a463943-7f58-42ea-9317-ba9f9518811e" except the ID changes. 

Any help?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sebtheoo
  • 125
  • 10

3 Answers3

2

To send a character sequence to the Email address field you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "input[name='emailAddress'][data-componentname='emailAddress']").send_keys("sebtheoo@stackoverflow.com")
    
  • Using xpath:

    driver.find_element(By.XPATH, "//input[@name='emailAddress' and @data-componentname='emailAddress']").send_keys("sebtheoo@stackoverflow.com")
    

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[name='emailAddress'][data-componentname='emailAddress']"))).send_keys("sebtheoo@stackoverflow.com")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='emailAddress' and @data-componentname='emailAddress']"))).send_keys("sebtheoo@stackoverflow.com")
    
  • 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
0

Try selecting element by Tag name

input_box = driver.find_elements_by_tag_name('tag_name_of_input_box')

or since it has a name attribute so you can try that as well

input_box = driver.find_element_by_name('emailAddress')

or as it also has a place holder so even you can combine the xpath with placeholder

input_box = driver.find_element_by_xpath('"//input[@placeholder='Email address']"')
Romeo
  • 5
  • 5
0

You need to check for tags that don't change. For example, in both the data, name is not changing. Hence you can move ahead with that.

To access element using name tag, try this syntax:

driver.findElement(By.name("emailAddress"));