0

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();
Gaurav Thantry
  • 753
  • 13
  • 30
  • did you try to increase the JVM memory ? when there is few memory avaiable the JVM is slower it could maybe fix your issue. there is to few information at my sense in your post to give you a better answer ^^ – Arnault Le Prévost-Corvellec Jun 16 '18 at 12:27
  • What happens on the page when you click? Does the page change or ? A link to the page would be helpful – JeffC Jun 16 '18 at 13:18
  • Hi @JeffC. Thank you for your reply. Unfortunately i wouldn't be able to give you the page link as it has restricted usage. It can be accessed from my office network. there are many frames in the webpage. So whenever a new value is being automated, it opens a new frame, keeping the existing frame in the background. So the xpath points to the elements in both the frames. – Gaurav Thantry Jun 16 '18 at 14:02
  • Hi @ArnaultLePrévost-Corvellec. It is still slowing down after 100 or 150 loops. – Gaurav Thantry Jun 16 '18 at 14:42
  • so the more you iterate the more there are different element that acces to same file? it s could be some synchronised object in your xpath lib that slow down your code, i suggest you to read https://examples.javacodegeeks.com/core-java/xml/xpath/java-xpath-performance-tips/ – Arnault Le Prévost-Corvellec Jun 16 '18 at 14:53
  • basically your problem look like this https://stackoverflow.com/questions/3782618/xpath-evaluate-performance-slows-down-absurdly-over-multiple-calls – Arnault Le Prévost-Corvellec Jun 16 '18 at 14:53
  • Hi @ArnaultLePrévost-Corvellec. In that question, the User is trying to loop using the Nodes. Here its a different scenario. I am just trying to add two string based on the iteration of the loop. – Gaurav Thantry Jun 16 '18 at 15:56
  • Hi everyone, I just realized that i asked the wrong question. corrected it now. I was working on it from a month, and didn't remember what was it doing. – Gaurav Thantry Jun 16 '18 at 16:05

0 Answers0