Updated
I'm using:
- Selenium 2.53.1
- Firefox and IE11
I've been trying to click on all elements with the same selector, for example, I want to click on all the ones with the title "What I Want"
:
<div id="first_question">
<a class="gibberish1" title="What I Want"></a>
<a class="gibberish2" title="What I Want"></a>
<a class="gibberish3" title="What I Want"></a>
</div>
Here is what I have working so far:
browser.findElements(by.xpath("//a[@title='What I Want']")).then(function(all_tests){
for (var i = 0; i < all_tests.length; i++) {
console.log(all_tests.length);
all_tests[i].click();
}
});
It's able to recognize that I have three elements, and if I call each individual one directly then I'm able to see it click on the button. However, when I want to loop so it clicks on each button, I get an error:
"StaleElementReferenceError: Element is no longer attached to the DOM."
I also added a wait of 5 seconds in, but that didn't deter the same issue from popping up.
What am I doing wrong? I'm new to Selenium and I'm trying to figure this out in Javascript, instead of Java which is what I find examples for this situation.