Hello everyone, I am new to using the Selenium webdriver and I'm struggling with implementing a for loop while utilizing the JavaScript executor. Can someone help me convert the code below into a loop structure? The code snippet involves changing the index value after div[6], as shown in this line: driver.findElement(By.xpath("//*[@id='unfreezedGridBody']/div[6]/div[5]/div/div/span[3]"));
Any assistance would be greatly appreciated.
// Loop through different elements on the page
for(int i = 1; i <= 5; i++) {
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement dropdowns = driver.findElement(By.xpath("//[@id='unfreezedGridBody']/div[6]/div[" + i + "]/div/div/span[3]"));
jse.executeScript("arguments[0].scrollIntoView()", dropdowns);
jse.executeScript("arguments[0].click();", dropdowns);
Thread.sleep(2000);
driver.findElement(By.xpath("//li[@data-content='PASS']")).click();
Thread.sleep(10000);
}