The title is my question.

I have a link like this:

<a href="">

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


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


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


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:


//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.

  • 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
    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/… 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.