1
driver.get("https://www.leafground.com/dynamicgrid.xhtml");
        
//count column
List<WebElement> column = driver.findElements(By.tagName("th"));
System.out.println(column.size());
        
//row 
List<WebElement> row = driver.findElements(By.tagName("tr"));
System.out.println(row.size()/2);
        
//return value of a customer
String text = driver.findElement(By.xpath("//td[normalize-space()='Costa Jennifer']//td[3]")).getText();
System.out.println(text);

What I'm trying to do is to get the activity value for Costa Jennifer value. But I'm getting:

Unable to locate the element.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • When you are getting this "Unable to locate.....", can you verify if "Costa Jenneifer" is present in the table? By the looks of it, the source is being changes on every refresh. Also, if "Costa Jennifer" was there, then still xpath is incorrect as in your xpath, it is trying to find td inside td. – hiren Dec 30 '22 at 11:51

1 Answers1

0

You need to improve your locators.
This will give you the table rows:

List<WebElement> rows = driver.findElements(By.xpath("//tbody//tr[@role='row']"));
System.out.println(rows.size());

To get activity value of some user you can locate the row by user name and then locate proper td cell value. As following:

String activity = driver.findElement(By.xpath("//tr[contains(.,'Munro Leon')]//td[4]")).getText();
System.out.println(activity);
Prophet
  • 32,350
  • 22
  • 54
  • 79