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.
Related
I have this piece of HTML and I'm trying to select the <a href> link using xpath.
<li class="footable-page-nav" data-page="next" aria-label="next"><a class="footable-page-link xh-highlight" href="#">›</a></li>
I need the selector to be reasonably specific since "footable-page-link" exists in multiple places in the HTML.
I've tried this:
//li[#class='footable-page-nav']/a[#class='xh-highlight']//#href
Selenium throws an error: selenium.common.exceptions.NoSuchElementException
If I shorten the xpath expression to //li[#class='footable-page-nav'] just to see if I'm on the right track then I get
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: element has zero size
What am I missing?
Try changing your xpath expression to
//li[#class='footable-page-nav']/a[contains(#class,'xh-highlight')]//#href
and see if it works.
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
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
I am trying to click on the link whose site is www.qualtrapharma.com by searching in google
"qualtra" but there is problem in writing xpath as <cite> tag contains <B> tag inside it. How to do any any one suggest?
<div class="f kv" style="white-space:nowrap">
<cite class="vurls">
www.
<b>qualtra</b>
pharma.com/
</cite>
<div>
You may overcome this by using the '.' in the XPath, which stands for the 'text in the current node'.
The XPath would look like the following:
//cite[.='www.qualtrapharma.com/']
I have some html that looks pretty much like this.
<p>
<a img src="img src">
<strong>foo</strong>
<strong>bar</strong>
<strong>baz</strong>
<strong>eek</strong>
This is the text I want to select using xpath.
</p>
How can I select only this particular text node as indicated above using xpath?
How do I get at only this particular
text element in question using xpath?
Use:
/p/text()[last()]
"/p/text()" xpath expression will select the text from "p" node in above XML (Posted in question).
/p/text()[normalize-space()]
this will remove trailing spaces from string. This xpath produces exactly what you want.
There is very good tutorial at http://www.w3schools.com/xpath/