Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我的所有页面数据显示StaleElementReferenceException_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 为什么我的所有页面数据显示StaleElementReferenceException

Java 为什么我的所有页面数据显示StaleElementReferenceException,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,显示堆栈溢出时出错 public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver","/home/arima/chromedriver/chromedriver"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(20

显示堆栈溢出时出错

public static void main(String[] args) throws Exception {
    System.setProperty("webdriver.chrome.driver","/home/arima/chromedriver/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
    driver.get("http://education-india.in/Education/Courses/?PageNumber=1");
    Thread.sleep(5000);

    List<WebElement> dropdown = driver.findElements(By.xpath("//select[@id='txtPageNumber']/option"));

    for(int k=1;k<dropdown.size()-1;k++) {
        List<WebElement> rows = driver.findElements(By.xpath("//table[@class='index']/tbody/tr"));
        List<WebElement> col = driver.findElements(By.xpath("//table[@class='index']/tbody/tr[1]/th"));

        for(int i=0;i<rows.size()-1;i++){
            System.out.println(rows.get(i).getText());
        }

        dropdown.get(k).click();
        Thread.sleep(4000);

        /*
         * WebDriverWait wait = new WebDriverWait(driver, 10);
         * wait.until(ExpectedConditions.presenceOfElementLocated(dropdown));
         */
    }
}
publicstaticvoidmain(字符串[]args)引发异常{
System.setProperty(“webdriver.chrome.driver”,“/home/arima/chromedriver/chromedriver”);
WebDriver驱动程序=新的ChromeDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
驱动程序。获取(“http://education-india.in/Education/Courses/?PageNumber=1");
睡眠(5000);
列表下拉列表=driver.findElements(By.xpath(//select[@id='txtPageNumber']/option”);
对于(int k=1;k
当webdriver无法识别该页面上的元素时,会出现错误。您需要在for loop中重新分配下拉元素。请尝试以下代码

driver.get("http://education-india.in/Education/Courses/?PageNumber=1");
    WebDriverWait wait=new WebDriverWait(driver, 30);
        List<WebElement> dropdown =wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//select[@id='txtPageNumber']/option")));


        for(int k=1;k<dropdown.size()-1;k++) {
            List<WebElement> newdropdown =wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//select[@id='txtPageNumber']/option")));

            List<WebElement> rows = driver.findElements(By.xpath("//table[@class='index']/tbody/tr"));
            List<WebElement> col = driver.findElements(By.xpath("//table[@class='index']/tbody/tr[1]/th"));

            for(int i=0;i<rows.size()-1;i++){
                System.out.println(rows.get(i).getText());
            }

            newdropdown.get(k).click();

        }
driver.get(“http://education-india.in/Education/Courses/?PageNumber=1");
WebDriverWait wait=新的WebDriverWait(驱动程序,30);
List dropdown=wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(//select[@id='txtPageNumber']/option));
对于(int k=1;k
当webdriver无法识别该页面上的元素时,会出现错误。您需要在for loop中重新分配下拉元素。请尝试以下代码

driver.get("http://education-india.in/Education/Courses/?PageNumber=1");
    WebDriverWait wait=new WebDriverWait(driver, 30);
        List<WebElement> dropdown =wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//select[@id='txtPageNumber']/option")));


        for(int k=1;k<dropdown.size()-1;k++) {
            List<WebElement> newdropdown =wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//select[@id='txtPageNumber']/option")));

            List<WebElement> rows = driver.findElements(By.xpath("//table[@class='index']/tbody/tr"));
            List<WebElement> col = driver.findElements(By.xpath("//table[@class='index']/tbody/tr[1]/th"));

            for(int i=0;i<rows.size()-1;i++){
                System.out.println(rows.get(i).getText());
            }

            newdropdown.get(k).click();

        }
driver.get(“http://education-india.in/Education/Courses/?PageNumber=1");
WebDriverWait wait=新的WebDriverWait(驱动程序,30);
List dropdown=wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(//select[@id='txtPageNumber']/option));

对于(int k=1;k),因为下拉菜单是一个选择元素。您可以使用选择对象来选择页面

陈旧元素引用错误的原因是每次加载页面时,下拉列表的定位器保持不变,但它不是相同的元素。下拉列表也会刷新。这就是为什么每次加载页面后都必须找到下拉列表的原因

试试这个:

driver.get(“http://education-india.in/Education/Courses/?PageNumber=1");
WebDriverWait wait=新的WebDriverWait(驱动程序,30);
wait.until(ExpectedConditions.elementtobelickable(By.id(“txtPageNumber”));
List options=driver.findElements(By.xpath(//select[@id='txtPageNumber']/option”);

对于(int k=0;k),因为下拉列表是一个select元素。您可以使用select对象来选择页面

陈旧元素引用错误的原因是每次加载页面时,下拉列表的定位器保持不变,但它不是相同的元素。下拉列表也会刷新。这就是为什么每次加载页面后都必须找到下拉列表的原因

试试这个:

driver.get(“http://education-india.in/Education/Courses/?PageNumber=1");
WebDriverWait wait=新的WebDriverWait(驱动程序,30);
wait.until(ExpectedConditions.elementtobelickable(By.id(“txtPageNumber”));
List options=driver.findElements(By.xpath(//select[@id='txtPageNumber']/option”);


对于(int k=0;k堆栈跟踪是什么?org.openqa.selenium.StaleElementReferenceException这是我的错误您想选择哪一个?我想一页一页地打印当前页面web表plzhelp各位..这一个显示StaleElementException什么是堆栈跟踪?org.openqa.selenium.StaleElementReferenceException这一个是我的错误您想选择哪一个?我想一页一页地打印当前页面的web表plzhelp各位..这一个显示StaleElementException这不是导致
StaleElementReferenceException
的原因。stale元素是您有引用的元素(存储在变量中)页面刷新更改的方式使您存储的确切元素不再在页面上。您所说的更像是一个
NoTouchElementException
@JeffC:当您检查其他人代码时,selenium抛出
StaleElementReferenceException
请尝试操作代码并检查您遇到了什么错误ng.当我运行OP code时,我得到了
StaleElementReferenceException
异常。OP还确认,如果您在注释框中看到OP注释。我说的是您对
StaleElementReferenceException
的解释。您说的
错误发生在webdriver无法识别该页面上的元素时。
这不是正确的rect.@JeffC:很抱歉,我可能会把解释写错。不过,解决方案是正确的。不过,我会记住,但我认为我不值得投反对票。为了写作。如何将此项存储在excel工作表中这不是导致
StaleElementReferenceException
的原因。StaleElement就是您有一个引用(存储在变量中)页面刷新更改的方式使您存储的确切元素不再在页面上。您所说的更像是一个
NoTouchElementException
@JeffC:当您检查其他人代码时,selenium抛出
StaleElementReferenceException
请尝试操作代码并检查您遇到了什么错误ng.当我运行OP code时,我得到了
StaleElementReferenceException
异常。OP还确认,如果您在注释框中看到OP注释。我说的是您对
StaleElementReferenceException
的解释。您说的
错误发生在webdriver无法识别该页面上的元素时。
这不是正确的rect.@JeffC:很抱歉,我可能会把解释写错。不过,解决方案是正确的。不过,我会记住,但我认为我不应该因为同样的原因投反对票。为了写作。如何在excel工作表中存储此项已满。但我想在excel工作表中存储此数据。请帮助如何操作此项是帮助已满。但我想将此数据存储在excel工作表中。请帮助如何执行此操作