-1

I'm using Selenium 2.53.1. I'm trying to select several elements that have the same xpath, but I keep getting a stale element reference error. I read in other posts that adding a wait would work, but I'm still getting this error.

browser.findElements(by.xpath("//a[@title='Run Test Suite']")).then(function(all_tests){
       // console.log(all_tests.length);
       for (var i = 0; i < all_tests.length; i++) {
           console.log(all_tests.length);
           all_tests[i].click();
           // browser.manage().timeouts().implicitlyWait(300000);
           browser.findElements(by.xpath("//a[@title='Run Test Suite']"));
           console.log("got to my wait");
           browser.manage().timeouts().implicitlyWait(10000);
       }
});

Do you have any suggestions on what I did wrong?

Lucia
  • 85
  • 1
  • 12
  • 3
    I would recommend you spend some time learning what a stale element reference is. That's crucial to learning how to fix the issue. – JeffC Jun 29 '17 at 17:03
  • Possible duplicate of [How Do I Click All Elements in Selenium Webdriver?](https://stackoverflow.com/questions/44805742/how-do-i-click-all-elements-in-selenium-webdriver) – lauda Jun 29 '17 at 19:06

1 Answers1

0

Do the click on xpath using an index, like
browser.findElement(by.xpath("//a[@title='Run Test Suite'][i]")).click();

Note that i used findElement without the last s since i wand to find just one.

If using the index in that way is not working then you need to find a common parent, this index will work for elements on the same level.

lauda
  • 4,153
  • 2
  • 14
  • 28