How to get value from the table? How to get value from the table? selenium selenium

How to get value from the table?


You can use List<List<String>> getRowsAsString() method to get all the values from your table. Then just check this collection with hamcrest matcher. So the final code will be pretty simple:

assertThat(table.getRowsAsString(), contains(contains(equalTo("ADMIN"))));


You can do this

WebElement adminSpan = driver.findElement(By.cssSelector("#usersForm:mainTable:n span[title='ADMIN']"));System.out.println(adminSpan.getText().trim());

I added the TABLE id just in case there is more than one of these admin SPANs. The CSS selector reads as find an element with an id (#) of usersForm:mainTable:n that has a descendant () SPAN with the title of ADMIN.

You may or may not need to trim(). I've gotten to the point where I just always trim() because it's easy and it saves me time finding and adding it later when I find out I needed it but didn't realize it. :)


Try to find out by installing firepathfind out the path by firepath