I am trying to print the values of the City column for different rows from the below table shown in the image.
I used the below code. My code prints "Dubai" 4 times instead of printing different cities. Can someone help me in fixing this?
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://toolsqa.com/automation-practice-table/");
WebElement body = driver.findElement(By.xpath("//*[@id='content']/table/tbody"));
List<WebElement> rows = body.findElements(By.tagName("tr"));
System.out.println(rows.get(0).findElement(By.xpath("//td[2]")).getText());
System.out.println(rows.get(1).findElement(By.xpath("//td[2]")).getText());
System.out.println(rows.get(2).findElement(By.xpath("//td[2]")).getText());
System.out.println(rows.get(3).findElement(By.xpath("//td[2]")).getText());