Issue
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)
Thanks
PS- The web email application is fastmail.com
Solution
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)
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.