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)'
Related
<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')]
This is what I have
1005523 Test-Test-P24-FAID-EUR
I want to write an XPath for the a based on its contained text. I tried the below but it does not work
xpath=(//a[contains(., "Test-Test-P24-FA")])
However, when I try this one, it works.
xpath=(//a[contains(., "Test-Test-P24-FAI")])
Do you have any suggestions?
Thanks!
Try any of this below mentioned xpath.
//a[contains(., 'Test-Test-P24-FAID')]
OR
//a[contains(text(), 'Test-Test-P24-FAID-EUR')]
OR
//a[text()='1005523 Test-Test-P24-FAID-EUR']
Explanation of xpath:- Use text method along with <a> tag.
OR
//a[#class='managed_account_link being_setup'][text()='1005523 Test-Test-P24-FAID-EUR']
Explanation of xpath:- Use class attribute and text method along with <a> tag.
OR
//a[#style='background-color: transparent;'][text()='1005523 Test-Test-P24-FAID-EUR']
Explanation of xpath:- Use style attribute and text method along with <a> tag.
I've been trying to get this using xpath:
<h1>Text1<nobr>Text2</nobr></h1>
xpath("//h1") gets both texts. Can't seem to figure out how to only get Text1.
Thanks in advance!
The following should return text node that is direct child of <h1> :
//h1/text()
Demo
Output :
Text1
I have below HTML sample code:
<a href="" title="Design" class="reMode_design reMode_hover">
<span>Design</span>
</a>
<a href="" title="Design"
class="reMode_design reMode_hover reMode_selected">
<span>Design</span>
</a>
Here, i need to define CSS for the 1st href element and want to ignore 2nd element which has this class "reMode_selected". How to define css for the 1st element by ignoring 2nd element???
I don't want to use Xpath and I am looking for like this below CSS selector:
element :fld_link, "[title='Design'] [class !='reMode_selected']"
This format doesn't work in SitePrism Cucumber. Need Help on how to exclude a attribute name in CSS selector...
You can do this with cssSelector
driver.find_element(:css,".reMode_design:not(.reMode_selected)")
You can do with this css locator a[title='Design']:not([class*='reMode_selected'])
Have you tried using an xpath to locate the element? Perhaps something like: //a[contains(#title, 'Design') and not(contains(#class, 'reMode_selected'))]
References/Examples:
Using not in xpath
Using and in xpath
You can use the not: css prefix as others have mentioned or you could combine a capybara query to return the element based off it's text, or use a waiter.
SitePrism is quite advanced, so pretty much all options are open to you
How do I get the Xpath that returns:
//www.example.com
With the following DOM:
<a id="myId" href="//www.example.com">
Click here</a>
//a[#id='myId']/#href
That should work, just implement it into whatever language you're using xpath with.