xpath=(//a[contains(text(),'-PPxo-P24-FA')])[2] fails to select - selenium

This is what I have
1000000 Venelin-PPxo-P24-FAID-EUR
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(text(),'-PPxo-P24-FA')])[2]
However, if I try with the below, it works
xpath=(//a[contains(text(),'-PPxo-P24-FAI')])[2]
I am using Selenium IDE 2.9.1 if that makes any contribution to my question.

Hi it seems your Xpath is incorrect
can you try following:
xpath = ("//a[contains(text(),'-PPxo-P24-FA')][2]")

Thank you for all of the answers, guys!
However, I found the solution. It looks like the website contains the text some more times than I need it to. The working code is:
xpath=(//a[contains(text(),'-P24-')])[6]

Related

How to find an element containing #nbsp; in text?

I've an element with html -
<h3>App-1 Playground Login</h3>
I want to identify it with entire text - App-1 Playground Login, but causing issues to identify it. Please help how this element can be identified.
Please use the below xpath. I have already tested that and it is working fine. In the second argument of the translate method you need to type "ALT+0160" and in the third argument you will have to put just a normal space.
//h3[contains(translate(text(),' ',' ' ), 'App-1 Playground Login')]
One of the way to select your title could be :
//h3[text()= concat('App-1 Playground',codepoints-to-string(160),'Login')]
Works fine on http://xpather.com/

How to combine two xpath into single xpath

Please find screenshot
Xpath Expressions are :
1.xpath
//td[.//span='Large' and .//span='Angelfish']
2.Xpath
//td[.//span='EST-1']
Above two xpaths, i want to merge it into single xpath. I tried the below
//td[.//span='EST-1' and .//span='Large' and .//span='Angelfish']
but no luck. Any help is appreciated...
I think you are talking about the JPetStore site Angelfish table, you can try the below Xpaths :
//td[span[text()='Large'] and span[text()='Angelfish']]/preceding::td/a[text()='EST-1']
or
//td[span[text()='Small'] and span[text()='Angelfish']]/preceding::td/a[text()='EST-2']
But I'm not sure what value you need from that because your question is not clear and the given information also not enough.

How to validate a text in selenium where multiple spaces in between two words?

I would like to know how to write the Xpath for validate the text -'Confirm Passowrd*' where there is more than 10 space gap between two words
When I tried to get it using chropath tool it gives Xpath like
//label[contains(text(),'Confirm Password*')]
But even that is also not working.
you can use the normalize-space in xpath.
//label[#ng-if='add_user' and normalize-space(text())='Confirm Password*']
You can also get text by:
driver.findElement(By.xpath("//label[#ng-if='add_user']")).GetAttribute("innerText");
OR
driver.findElement(By.xpath("//label[#ng-if='add_user']")).GetAttribute("value");
driver.findElement(By.xpath("//label").GetAttribute("value");

Find specific cell of a celltable with Selenium xpath

I have a celltable , where i have multiple rows and is a dynamic table,
Screenshot attached ..
What i want is to find the row where column contains useren#lim.mobi
and then click its checkBox.
I am trying with xpath but not much experience here , If i can get some help please
Thanks
Here is the html code of the specific cell
I don't know the exact html of your table to form an xpath would be difficult.
however it should look something like this
//*[contains(text(),'useren#lim.mobi ')]/../td[2]
for following table, if I have to find the corrosponding contact for some company, This is how I would do it.
https://www.w3schools.com/html/html_tables.asp
//*[contains(text(),'Magazzini Alimentari Riuniti')]/../td[2]
Please try with the following xpath:
//tr[./td[contains(text(),'useren#lim.mobi')]/td[2]/input
if above xpath is not working please attach html code screenshot so i can tell you the extact xpath.
This might help to solve your issue:
//td[#title="useren#lim.mobi"]/following::input[#type="checkbox"]
If you get NoSuchElementException with this XPath you might need to add ExplicitWait as below:
WebElementWait wait = new WebElementWait(getWebDriver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//td[#title='useren#lim.mobi']/following::input[#type='chec‌​k‌​b‌​ox']")));

Xpath for href element

I need to click on the below href element,which is present among similar href elements.
<a id="oldcontent" href="listDetails.do?camp=1865"><u>Re-Call</u></a>
Can anyone provide me xpath to click the above href link?
Try below locator.
selenium.click("css=a[href*='listDetails.do'][id='oldcontent']");
or
selenium.click("xpath=//a[contains(#href,'listDetails.do') and #id='oldcontent']");
This works properly try this code-
selenium.click("xpath=//a[contains(#href,'listDetails.do') and #id='oldcontent']");
This will get you the generic link:
selenium.FindElement(By.XPath("xpath=//a[contains(#href,'listDetails.do')")).Click();
If you want to have it specify a parameter then you will have to test for each one:
...
int i = 1;
selenium.FindElement(By.XPath("xpath=//a[contains(#href,'listDetails.do?camp=" + i.ToString() + "')")).Click();
...
The above could utilize a for loop which navigates to and from each camp numbers' page, which could verify a static list of camps.
Please excuse if the code is not perfect, I have not tested myself.
have you tried:
//a[#id='oldcontent']/u[text()='Re-Call']
for me worked //a[text()='Re-Call']
what worked for me:
//a[contains(#href,'logout')]
Below works fine.
//a[#id='oldcontent']
If you've tried certain ones and they haven't worked, then let us know, otherwise something simple like this should work.
Best way to locate anchor elements is to use link=Re-Call:
selenium.click("link=Re-Call");
It will work..