rickypc / selenium-page-object-generator

A nimble and flexible Selenium Page Object Model generator to improve agile testing process velocity.

Home Page:https://chrome.google.com/webstore/detail/epgmnmcjdhapiojbohkkemlfkegmbebb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access anchors by link text, not href

hubertgrzeskowiak opened this issue · comments

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.

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

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

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