How to combine two xpath into single xpath - selenium

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.

Related

How to Find an xpath with some string contained and some not contained in the div?(Xpath not contains)

**Problem :** How to Find an xpath with some string contained and some not contained in the div?(Xpath not contains)?
**Below are three examples**
1)<div>You are now connected to Customer Care Virtual Assistant.</div>
2)<div>You are now connected to sumit.</div>
3)<div>You are now connected to dev.</div>
I have tried *//*[contains(text(),'You are now')]*
this xpath as well but it gives me 3 results and want only to fetch for values which does not contain virtual
i am currently using this xpath - *//*[text()[contains(.,'You are now ') and not[contains(.,'Virtual')]]*
It's not working for me , let me know what mistake i am doing here.
Any help will be appreciated ,
Thanks
You were close.Try the following xpath.
//*[contains(.,'You are now') and not(contains(.,'Virtual'))]
Try another solution
//a[not(contains(text(), 'Virtual')) and contains(.,'You are now')]
or
//a[not(contains(text(), 'Virtual')) and contains(text(),'You are now')]
maybe you can use:
1- use "starts-with" function.
div[starts-with(#id,'something')]
2- use "contains" function.
div[contains(#id,'something')]
or
3- use full xpath, that id is not necessary to use attributes
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/div[2]/div[1]/form[1]/input[1]

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

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]

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

How to use array of XPath in robotframework

I have html table which has some one column and N rows. I want to traverse through the array. Since HTML table does not have unique locator. I am using #class attribute to get the rows This is my xpath which gives me matching rows.
//td[contains(#class,'td-entity-field-super-parent')].
When i add index to it like this:
(//td[contains(#class,'td-entity-field-super-parent')])[3],
it works fine in firebox/seleniumIDE.
However with RobotFramework, it works only for first row.
Works:
//td[contains(#class,'td-entity-field-super-parent')][1]
Does not work:
//td[contains(#class,'td-entity-field-super-parent')][2]
//td[contains(#class,'td-entity-field-super-parent')][3]
//td[contains(#class,'td-entity-field-super-parent')][4]
BTW, enclosing entire element in round bracket does not work.
(//td[contains(#class,'td-entity-field-super-parent')])[4]
Can someone please help me here.
Ok. Here is the answer. Simply use "xpath=" as prefix to your xpath. Here is the example
xpath=(//td[contains(#class,'td-entity-field-super-parent')])[4]