New to Selenium-TestNG-Java
I'm trying to find an number on a webtable and click it, as I want to be able to pick the correct number on the list. Or get the location of said number so I can select that row by clicking the first element.
This is the one I need to "pinpoint"
But the only thing I have is the Xpath ( //*[#id="multisujetoSociosTable"]/tbody/tr/td[5]/b ) and inside it is the number I need "< b >33210266801< / b >"
Any idea or tip?
Thanks for any answer.
Did you try using an xpath using text() to check the containing text?
//*[#id="multisujetoSociosTable"]/tbody//tr/td[text()='33210266801']
you could also combine with contains:
//*[#id="multisujetoSociosTable"]/tbody//tr/td[contains(text(),'33210266801')]
Like mentioned above 'get.text()' should to the trick
Related
I have a dynamic webtable where it has ID column. I want to get all links from this ID column and click on it one by one. Should I use list to save all the values and using for loop iterate through it? I am new to webdriver so not sure about it.
Yes you can simply use list and store all the links.
I have a list of many hyperlinks by below text :View / Select Monitors. So I stored all the links simply in a list.
And then I can click on any link by passing the value I want.
If you want to click on all the links then you can simply use a for loop and click it.
For example:
List<WebElement> list = driver.findElements(By.linkText("View / Select Monitors"));
//Click on first hyperlink with matched text
list.get(0).click();
2nd Example:
Step1.[Getting all the links by tagname]
List<WebElement> allLinks = driver.findElements(By.tagName("a"));
Step2. [Storing the total size for the number of links]
int s =allLinks.size();
Step 3.[I am printing all the links here and there position]
for(int i=0;iString txtlink=allLinks.get(i).getText();
System.out.println("%n"+i);//Getting the value of i and hyperlink
System.out.println(txtlink);
allLinks.get(i).click;//You can simply pass the value of i and
click on it
`Thread.sleep(2000)'
}
In this way you can get the value of "i" also and then click if you like if you need to click on any particular link and if you want to click on all then simply use .click inside the loop.`enter code here`
I hope it helps.
I'm trying to select partially an element with xpath in my selenium code.
My xpath is
//iron-pages[#id='pages']//span[.='s8718216']
what I want is to select any element starting with s, the element just after span.
I tried this:
//iron-pages[starts-with(span[.='s'])
It doesn't work for me.
Can someone help me.
I think this xpath should work //iron-pages[starts-with(text(),'s')]
Or second try:
//iron-pages[starts-with(.,'s')] <- . instead of text() checks element for more properties. Not only text.
There are many properties that might contain text like innerText, innerHTML etc.
EDIT:
I just read your question again. You want to select element right after span so:
//iron-pages[#id='pages']//span[starts-with(text(),'s')] <- it will select span elements starting with text s.
If you want child elements you can use
//iron-pages[#id='pages']//span//*[starts-with(text(),'s')]
Your xpath should be
//iron-pages[starts-with(span[.='s'])//following-sibling::i[1]
it will get the next element that start with span with text s
I want to perform below scenario.
1) I enter a name using sendkeys() and then click on search button.
2) Once I get the search results, I need to click on name which i searched for.
How do I verify and click using selenium webdriver Java.
Its a href="/cc/name.html" target = "_blank">Name.c James/a
As Saad said you could add 2 controls to be sure of the results is what you are expecting
Check only 1 eleent of the expected result is in the page. (Maybe you need to find inside some specific container first)
From that webElement compare the name
getDriver().findElements(By.tagName("a")).size() == 1
&& getDriver().findElements(By.tagName("a")).get(0).getText().equals("Name.c James/a")
If your search result is unique. Only 1 record will exist. If you are clicking on name, I'm assuming that it will redirect user to the next screen. So, get the relative xpath of the name and use click() .
Thanks :)
Well...I think I still haven't figured out how xpath works. I am trying to select the below element so that I can click on the second page. But what I am trying does not work. What is wrong here? I am selecting the a tag and then trying to find the one which contains ref whose value is next.
element = driver.findElement(By.xpath("//a[contains(#ref,'next')]"));
I probably see a typo there. The attribute you are trying to use is rel which has value next
So the correct xpath will be
//a[contains(#rel,'next')]
Im doing a test that enter text in the textbox but it dont have specific ID so everytime i run the test it will change. im using selenium webdriver in java please help
The following can work. You can google for them and see how they work.
driver.findElement(By.id("id"));
driver.findElement(By.cssSelector("cssSelector"));
driver.findElement(By.name("name"));
driver.findElement(By.linkText("linkText"));
driver.findElement(By.partialLinkText("partialLinkText"));
driver.findElement(By.className("className"));
driver.findElement(By.xpath("xpath"));
I am sure some of them will be useful. Please let me know if you want more info.
The easiness of using them is in the order which i have mentioned.
What means doesn't have a specific ID?If id at least partially remains the same you can use the CSS locator
driver.findElement(By.cssLocator("input[id*=somePartWhichNotChange]"));
//* star means contains
if not, then you can use cssSelector to get to your element like "body table input" or use xpath as a last resort.