Elements - Multiple locators for same element

73 views
Skip to first unread message

Aionitoaie Andrei

unread,
Dec 2, 2019, 2:17:16 PM12/2/19
to Watir General
Hi,

Does Watir has something like identifying the same element using multiple locators? Something like Appium has: @AndroidFindBy and @IOSFindBy?

Or maybe some suggestions about how to achieve this?

Thanks,
Andrei

Titus Fortner

unread,
Dec 2, 2019, 3:38:45 PM12/2/19
to Watir General
Watir allows you to locate elements with multiple locators with an implied "AND" it does not support multiple locators with an "OR" evaluation.

What is supported is described here: http://watir.com/guides/locating/

Aionitoaie Andrei

unread,
Dec 4, 2019, 6:32:24 AM12/4/19
to Watir General
Thanks,

I was looking something more like OR evaluation.

Titus Fortner

unread,
Dec 4, 2019, 9:40:37 AM12/4/19
to watir-general
Right, I'm not a big fan of that pattern, as it makes executing deterministic tests more challenging. If you want to use it to apply to multiple views like mobile/desktop, you're going to introduce race conditions. If you want to use it to minimize brittleness you run the risk of testing the wrong thing.

Requiring explicitness in this case is a feature not a bug.

--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/watir-general/2205db86-bb17-4fb0-8f44-4c7137f65254%40googlegroups.com.

Justin Ko

unread,
Dec 4, 2019, 11:13:17 AM12/4/19
to Watir General
Hi Andrei,

Do you have an example of where an OR evaluation is useful?

As Titus said, it's not usually the way to go. That said, I'm pretty sure I've done it before. The solution usually depends on what you are trying to do and the page. For example:
  • If you wanted to match elements with the class of "A" or "B", but not "C", you could use a regular expression.
  • Some times I have found that looking at an ancestor or descendant element can remove the need for an OR condition.
  • If there is really nothing in common between the elements you can always brute force it by creating a list of elements and using the first that exists - eg found_element = [browser.div, browser.span].find(&:exists?)
 Justin


On Wednesday, December 4, 2019 at 9:40:37 AM UTC-5, Titus Fortner wrote:
Right, I'm not a big fan of that pattern, as it makes executing deterministic tests more challenging. If you want to use it to apply to multiple views like mobile/desktop, you're going to introduce race conditions. If you want to use it to minimize brittleness you run the risk of testing the wrong thing.

Requiring explicitness in this case is a feature not a bug.

On Wed, Dec 4, 2019, 6:32 AM Aionitoaie Andrei <andre...@gmail.com> wrote:
Thanks,

I was looking something more like OR evaluation.

luni, 2 decembrie 2019, 22:38:45 UTC+2, Titus Fortner a scris:
Watir allows you to locate elements with multiple locators with an implied "AND" it does not support multiple locators with an "OR" evaluation.

What is supported is described here: http://watir.com/guides/locating/


On Monday, December 2, 2019 at 1:17:16 PM UTC-6, Aionitoaie Andrei wrote:
Hi,

Does Watir has something like identifying the same element using multiple locators? Something like Appium has: @AndroidFindBy and @IOSFindBy?

Or maybe some suggestions about how to achieve this?

Thanks,
Andrei

--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages