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?

3 Answers 3

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("[email protected]")
    
  • Using xpath:

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

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("[email protected]")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='emailAddress' and @data-componentname='emailAddress']"))).send_keys("[email protected]")
    
  • 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
    
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot this has worked really well.
How can I access an element by it's what's contained in the <span>
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']"')

Comments

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"));

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.