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

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");

Related

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.

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

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]

How to find exact value using xpath in selenium webdriver?

I am using XPath to find exact value:
//h5[#class='familyName productFamilyName'][contains(text(),'Dozers ')]
but it was failing because in my application there are 2 elements with text values "Dozers " and "Dozers wheel" which is come under same class.
I can't use id locators,because it is dynamically generating in my application like //div[#id="482"]/div/div[1]/h5.
Please suggest me any solution.
If you want to match element with exact innerHTML value just use
//h5[#class='familyName productFamilyName'][text()='Dozers')]
or
//h5[#class='familyName productFamilyName'][text()='Dozers wheel')]
Depending on HTML structure you might need to use [.='Dozers'] or
[normalize-space(.)='Dozers'] instead of [text()='Dozers']

xpath - upper case and lower case button text

I have multiple ok buttons in my application in the combinations: OK, ok, oK and Ok. How can i write a single #findby expression to identify all of them with the one webelement.
Code example
<button type="button">OK</button>
Here is the other solution in pure xpath 1.0 using xpath functions.
//button[contains('OK,ok,Ok,oK',text())][string-length('OK')=2]
or
//button[contains('OK,ok,Ok,oK',text())][string-length(text())=string-length('OK')]
Edit: Simple approach using translate
//button[translate(text(),'ok','OK')='OK']
You can specify matching text with xpath:
//button[text()='OK']
In your case, to match them all:
//button[text()='OK' or text()='oK' or text()='ok' or text()='Ok']

Not able to identify a lenghty linktext in selenium webdriver

I want to identify an element by linktext, I am facing strange issue
If the linktext value is short i.e addFirst, addLast will be able to locate the element by using
driver.findelement(By.linktext("addLast, addFirst")).click
IF the linktext is addmanualreferraltocheckthelenghtF, addmanualreferraltocheckthelenghtF lengthy as above not able to identify the element
Please help me to find the solution
Why don't you try partial link text.
driver.findelement(By.partialLinkText("addLast, addFirst")).click
try out contains method. use the XPATH value and in XPATH use contains for link text.
EG:
.//*[contains(#Linktext, "addmanualreferraltocheckthelenghtF")]
driver.findelement(By.xpath("//*[contains(#Linktext, "addmanualreferraltocheckthelenghtF")]").click
Alternatively you can also use starts with XPATH value.
.//*[starts-with(#linktext,'addmanual')]
driver.findelement(By.xpath("
//*[starts-with(#linktext,'addmanual')]").click
Hope it helps you.