rickypc / selenium-page-object-generator

A nimble and flexible Selenium Page Object Model generator to improve agile testing process velocity.
https://chrome.google.com/webstore/detail/epgmnmcjdhapiojbohkkemlfkegmbebb
GNU Affero General Public License v3.0
122 stars 66 forks source link

Access anchors by link text, not href #12

Open hubertgrzeskowiak opened 8 years ago

hubertgrzeskowiak commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

@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: