Using selenium IDE- I am looking for a way to locate and or verify a value in a table. There are more columns in the table, but I am only concerned with the first 4. Also the number of rows varies as well as the location of the value I am looking for.
So, say, I am looking for username there. the username = "fred", who could exist in any row 1 to 10.
How could I locate and verify that user exist?
enter image description here
-
2Please post your HTML-Code as code not as imagebish– bish2015年10月27日 04:43:29 +00:00Commented Oct 27, 2015 at 4:43
-
yes actual code so we can copy and paste when makin our answers pleaseMichael Durrant– Michael Durrant2016年03月25日 15:57:06 +00:00Commented Mar 25, 2016 at 15:57
5 Answers 5
Personally the best way I have found is to loop through the table rows, then get the text from the you need to and compare. Below I have an example of what you can use, it should be easy enough to change to your liking.
public boolean searchUsername(WebDriver driver, String username){
boolean isFound = false;
List<WebElement> rows = driver.findElements(By.cssSelector("tbody > tr"));
for(WebElement row : rows){
if(row.findElement(By.cssSelector("td:nth-of-type(2)").getText.equals(username){
isFound = true;
break;
}
}
return isFound;
}
It is two different task in selenium IDE.
Maybe do
assertText
table td(3).text
='fred'
Will look in all the column 3 values
You can loop through the tds of table.
You need to first capture the table id or the div under which table is located. then using this element you have to loop through all td and check td's text == "fred".
Verifytext can be used to verify text exist within the table. enter image description here
Explore related questions
See similar questions with these tags.