0

The title is my question.

I have a link like this:

<a href="http://192.168.0.199/api/users/confirm-register/86fd8faa8fc23a2c4c5203fae252c3d02458093f">
http://192.168.0.199/api/
<wbr>
users/confirm-register/
<wbr>
86fd8faa8fc23a2c4c5203fae252c3
<wbr>
d02458093f
</a>

The problem is that the part after "/confirm-register/" is generated every time and is different.

How can i click on it? Keep in mind we know the href starts with "http://192.168.0.199/api/users/confirm-register/" and there is no id.

PS: There is a sentence before this link and other after which both are static. (If that helps someway) Example:

Here is some text

<a></a>

Here is another text

This is also contained in a table thats in another table and so on, but those tables have no id or name, only style.

Maybe if find the cell or table that contains both texts and then click on w/e link there is in it?

2 Answers 2

1

You can use xpath to find the element based on the part of the href you know

//a[contains(@href,'api/users/confirm-register/')]
0
0

Looking for link text is always fragile, for you depend both on the SUT and the linked application.

The most stable feature in your elements are the classes, so:

xPath:

//div[contains(@class, 'class_name') a

or the prefibable way, using CSS Selectors:

div.class_name a

Maybe it would be interesting create a test to validate the link itself, using the code indicated by JSmith. The test for the redirection on clicking is a different one.

2
  • Thanks, but what if the div share the same classes with many elements? Are those <wbr> accessible in any way for the xpath to identify it from others?
    – user25268
    Commented Apr 24, 2017 at 15:21
  • 1
    I've never dealt with <wbr>, but it seems WebDriver can see these tags. Following using class names, creating locators that are more specific, going through the DOM tree structure is another good practice. github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/… Commented Apr 24, 2017 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.