Xpath as a selector in hash format. Am I doing it wrong?

89 views
Skip to first unread message

Steve Parrado

unread,
Mar 27, 2019, 12:24:30 PM3/27/19
to Watir General
So while tooling around on some stuff, I was trying different ways to use selectors in conjunction with some array values.  I came across something that I can't quite figure out.

I recreated it using http://automationpractice.com/index.php to be able to ask in general without need for people to be in my environment to emulate.

So some details:
Ruby version:  ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
Watir version:  6.11.0
Chromedriver version:  2.46.628402

I know I am not at the latest for Watir and Ruby, I've had to lock in these version.

In anycase, at the url I mentioned above http://automationpractice.com/index.php I inspected the shopping cart element
I noted that the element had a title of "View my shopping cart" and I copied the xpath of "//*[@id='header']/div[3]/div/div/div[3]/div/a" (double quotes changed to single

The oddity that I am trying to figure out is this:

@browser.element(title: "View my shopping cart").present?  - evaluates true
@browser.element(:title, "View my shopping cart").present? = evaluates true
 @browser.element("title" => "View my shopping cart").present? - evaluates true

however,

@browser.element(xpath: "//*[@id='header']/div[3]/div/div/div[3]/div/a").present? - evaluates true
@browser.element(:xpath, "//*[@id='header']/div[3]/div/div/div[3]/div/a").present? - evaluates true
@browser.element("xpath" => "//*[@id='header']/div[3]/div/div/div[3]/div/a").present? - evaluates false

I tried this with some other elements to similar results

@browser.button(:name, "submit_search").present? - true
@browser.button(name: "submit_search").present? - true
@browser.button("name" => "submit_search").present? -true

@browser.button(xpath: "//*[@id='searchbox']/button").present? - true
@browser.button(:xpath, "//*[@id='searchbox']/button").present? - true
@browser.button("xpath" => "//*[@id='searchbox']/button").present? - false

Can anyone enlighten me on what I am doing wrong?

Thanks,
Steve

Titus Fortner

unread,
Mar 27, 2019, 12:46:40 PM3/27/19
to watir-general
:xpath as key is "locate an element with provided xpath value"
"xpath" as key is "locate an element with an attribute of 'xpath' that
has the provided value"

The goal of Watir, in general, though, is to make it so you should
never need to use XPath.
> --
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages