I have been writing an xpath of an element, for which the instance changes by its count. Say I have 100 values for which I have to automate one bay one from an excel file, the instance of the xpath of an element while automating for the first value is 1, and the next can be 2 or 3 or 1. It can be any one count of the closePath. The speed to search for the element keeps slowing down as I go down the list. Below is my code:the xpathNumber
adds the instance to the xpath on every run.
driver.switchTo().defaultContent();
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
int closePaths = driver.findElements(By.xpath("//*[text()[contains(.,'Message Map Data - View and Edit the Message Map Data')]]/following-sibling::div[@id='fb_buttons']/span[2]")).size();
for (int j = 1; j <= closePaths; j++) {
String closePath = "(//*[text()[contains(.,'Message Map Data - View and Edit the Message Map Data')]]/following-sibling::div[@id='fb_buttons']/span[2])";
String xpathNumber = "[" + j + "]";
closePath = closePath + xpathNumber;
try {
driver.findElement(By.xpath(closePath)).click();
} catch (Exception e) {}
}
driver.switchTo().defaultContent();
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(2));
driver.findElement(By.id("navFind1")).click();