I m using selenuim webdriver, lang: java
I am fetching all links from webpage and trying to click each link one by one.
1) I am getting below error: error org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up Command duration or timeout: 30.01 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
2) it's displaying in output "[[FirefoxDriver: firefox on XP (ce0da229-f77b-4fb8-b017-df517845fa78)] -> tag name: a]" as link, I want to eliminate these form result
and here is my code : public void getLinks()throws Exception{
try {
List<WebElement> links = driver.findElements(By.tagName("a"));
int linkcount = links.size();
System.out.println(links.size());
for (WebElement myElement : links){
String link = myElement.getText();
System.out.println(link); System.out.println(myElement);
if (link !=""){
myElement.click(); Thread.sleep(2000); System.out.println("third");
} //Thread.sleep(5000);
} }
catch (Exception e){
System.out.println("error "+e); } }
Please help
You are getting a stale element exception because the DOM has changed after you have clicked a link (either because you have been navigated to a new page or reloaded the DOM on the old page).
You would need to re-find the element after each click to eliminate the stale element exception.
What are you trying to do?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/FWmpT5GuxksJ.
For more options, visit https://groups.google.com/groups/opt_out.
Maybe I’m not being clear, why do you want to click each link? Do you just want to check the link isn’t dead?
If so something like this would be easier:
It’s explained on this blog entry:
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of shami
Sent: 20 November 2012 04:45
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: how fetch all links and click those licks one by one using selenium webdriver
1) I want to fetch and display all links on webpage.
2) after displaying, I am want to click each link one by one.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/A-jCBRUcZa0J.
public void getLinks()throws Exception{try {
List<WebElement> componentList = driver.findElements(By.tagName("a"));int numberOfElementsFound = getNumberOfElementsFound(By.tagName("a"));for (int pos = 0; pos < numberOfElementsFound; pos++) {if (getElementWithIndex(By.tagName("a"), pos).isDisplayed()){getElementWithIndex(By.tagName("a"), pos).click();}}
getElementWithIndex(By.tagName("a"), pos).click(); // it shows error in click() method
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/Gmw3Zsq0-Gg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d554d3ca-41c7-49bb-919d-d13abd8b37c7%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/2094d224-be94-420a-a7d6-29fd8081ccb5%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b38261f8-e456-434f-83d4-6318a34d13aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CABym8R%2BE9sKUCC8%3D2x6DLt4%3DpwUftvcyWYmATN1DNTW1bLS8MA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAJk%2BML2S_5vWX9eGDmUYwuR58SvSQNkT32Kk9Rf58fGJ2U6wsA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAJPyTs3e8%3D2iigBHWBuM2j-p3jfh_NYt%3DF%3DzSkE-Lb5ew5%3DMnA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAJk%2BML1YWk%2BYBhkx7HcrpyjKK2EH%3DOA2idh8LRBMbO0CHCvjgw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CABym8RJP1oNgTxWs5v4bm89U%3D4SFEjFsfKNO%3DrZzRx-6E5%2BkKw%40mail.gmail.com.