Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access anchors by link text, not href #12

Open
hubertgrzeskowiak opened this issue Jul 18, 2016 · 2 comments
Open

Access anchors by link text, not href #12

hubertgrzeskowiak opened this issue Jul 18, 2016 · 2 comments

Comments

@hubertgrzeskowiak
Copy link

In many dynamic applications the link targets change with query params because of session IDs, JavaScript, search params etc.

I think, in most cases it would be better to locate anchors by their containing text (or at least the first words of it) using XPath.

@BogdanLivadariu
Copy link

@hubertgrzeskowiak what happens if the site has more than one language ? :)

Would the element located by the first words of an anchor still work ?

@hubertgrzeskowiak
Copy link
Author

@BogdanLivadariu Same question could be asked for URLs. Language is most often set as sub-domain, first part of the path, or as query param. In my experience, on dynamic pages, the URLs change more often than texts.

Having links defined by text would be much easier to maintain whenever the pages change. Imagine your Selenium telling you that a link with URL www.example.com/order/invoices-cust0031?filter=by-date&sid=168754678&order=date cannot be found on page. You would need to know what that URL means or meant and if it has changed. On the other hand, imagine Selenium telling you that a link with text "show invoices" cannot be found. In this case, only domain knowledge is required and you can easily check the current page for a link with similar sounding text.

There are two problems with my suggestion, though:

  • What about links with an image inside?
  • What if multiple links have the same text? (e.g. "show more" or "expand")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants