1

I'm trying to use Selenium to find a web element that I know is the To field in a web email application (please see picture). I am able to successfully identify this web element and use send_keys to send an email address to this field.

However, the issue is the id always seems to cycle between 299 and 3 other numbers like 359 or 369. Here's the code Im using. Is there another way I can account for this changing ID?

to_field = wait.until(EC.element_to_be_clickable((By.ID, "v299-to-input")))
print(to_field)
to_field.send_keys(email_reciever)

enter image description here

Thanks

PS- The web email application is fastmail.com

2 Answers 2

1

Since the ID attribute is changing, you have to build your locator on some other, stable parameter. The following CSS Selector is stable:

to_field = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".s-compose-to textarea")))
print(to_field)
to_field.send_keys(email_reciever)

The same can be done with the use of XPath locator:

to_field = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class,'s-compose-to')]//textarea")))
print(to_field)
to_field.send_keys(email_reciever)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use following css selector to identify the element.

to_field = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea[id$='-to-input']")))
print(to_field)
to_field.send_keys(email_reciever)

This will identify the element id ends with the -to-input static value

to_field = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.v-EmailInput-input")))
print(to_field)
to_field.send_keys(email_reciever)

This will identify the element with tagname.classname

5 Comments

The second part will not work since that locator is not unique
@Prophet : how? this is the classname and i can't see any dynamic value in it v-EmailInput-input.
You didn't open the email composing page on fastmail.com but I do :) There are 4 elements matching this locator there
@Prophet : Ok got your point, That's true I didn't check the url :-)
It's not just URL. You will have to pass registration there

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.