Reputation: 113
I am trying to locate an href
element for some time now without any success.
String EMAIL_NOTIFICATIONS_PAGE = "[ng-href=\"#/settings/notifications/48\"]";
The number keeps changing. Sometimes selenium is able to locate the element and press it but sometimes it's not. I noticed that the number keeps changing.
I attached 2 screenshots.
Any suggestion how to locate an element that its href
changed on the run?
Upvotes: 0
Views: 77
Reputation: 4749
You can use any of these XPaths:
//a[contains(text(),'Email notification settings')]
or:
//a[contains(@href,'#settings/notifications/18')]
or:
//a[@href='#settings/notifications/18']
Upvotes: 0
Reputation: 945
If this is changed dynamically you could try something like:
driver.findElement(By.xpath(".//a[contains(text(), 'Email notification settings')]"));
This depends on text and it's not best practice, but it probably should work.
Upvotes: 1
Reputation: 111
also you can try
driver.FindElement(By.LinkText("Email notification settings"));
Upvotes: 0
Reputation: 6459
You can use CSS selector for identification all a tags: .t6.s10.clickable.no-underline
.
Then access to the needed element by using the index in the list (array).
Upvotes: 0
Reputation: 659
You can find all href elements, and check its text to specific content, your occasion is Email notification settings
. I always use this method if I can not have a clean and simply method to locate an element.
Upvotes: 0