How to find Xpath? - xpath

is there any easy way to find xpath ?
<span class="r5">5</span>Google
what will be the xpath of r5 ?
Thanks..

span[#class='r5']

Related

Xpath Get href inside attribute

I would like to know how can I write xpath to get what is inside href quotes here :
<a rel="test" href="/tf-265-exemple">mountain</a>
I tried xpath : //a[#rel='test']/#href
but not working so much
Regards
Try this :
'string(//a[#rel="test"]/#href)'

How to write the xpath for span tag

<span class="autoSuggKeywords">
samsung
refrigerator
</span>
i want to access the content refrigerator using xpath
objective :identify the element using Autosuggestion
i tried below
.//span[#class="autoSuggKeywords"]
.//[text()='refrigerator']
Try following solution :
//span[contains(#class, 'autoSuggKeywords') and text() = 'refrigerator']
Hope it will help you.
xpath expression:
//span[#class="autoSuggKeywords" and contains(.,'refrigerator')]

Xpath not contains

Is there a way to select the xpath which doesn't contain ng-show
Please find the xpath below:
I'm familiar with not(contains()), but it has 2 parameters.
I would like it to not contain the ng-showitself, because I have a few more element containing ng-show and I don't want to select any of them.
<span ng-show="displayValue" class="ng-binding">0 km</span>
Thanks in Advance
Try this below xpath
//span[not(#ng-show)][not(#class='percent ng-binding')][#class='ng-binding']
Explanation of xpath:- Only those <span> tag will return, which attribute does not contains ng-show

Selenium XPath for a table

Given this html segment:
<strong style="background-color: transparent;">53°F</strong>
How to retrieve the 53°F text? I tried
sel.getText("//parent_selector/**strong[text()**]"))
but this is not working.
Try this one :)
selenium.getText("xpath=//table[#class='twc-forecast-table twc-second']//tr[4]//strong");

How to access element using Watir and XPath

I have some HTML that looks like this:
<h1 id="header">Header</h1>
I would like to click it using Watir and XPath.
After watir-webdriver 0.5.1 selecting random element with an xpath was updated to:
browser.element(:xpath => "//h1[#id='header']").click
thanks to:
https://groups.google.com/forum/#!topic/watir-general/c6Orvy7Qalw
browser.element_by_xpath("//h1[#id='header']").click
Sources:
http://wiki.openqa.org/display/WTR/XPath
http://zeljkofilipin.com/2007/07/03/find-element-by-xpath/
browser.h1(:xpath, "//h1[#id='header']").click
Also not XPath, but works:
browser.h1(:html, /header/).click
Not using XPath, but it works:
browser.h1(:id, "header").click
Another example using xpath here:
browser.element xpath: "//div/cite[contains(.,'some text')]/ancestor::div[#class='rc']/h3/a"
Checkout this simple framework that I uploaded to Github:
https://github.com/atfuentess/watir_cucumber_automation/
The stack used is: watir/cucumber/rspec
Perhaps it can help someone.

Resources