Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.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
Maven/Java爬虫-StaleElementReferenceException_Java_Maven_Selenium_Web Crawler - Fatal编程技术网

Maven/Java爬虫-StaleElementReferenceException

Maven/Java爬虫-StaleElementReferenceException,java,maven,selenium,web-crawler,Java,Maven,Selenium,Web Crawler,我收到一个StaleElementReferenceException,但我不知道为什么?爬虫程序工作正常,并在排队的URL中循环,但由于StaleElementReferenceException错误而失败 任何帮助都将不胜感激 下面是代码和错误 代码 package com.crawlerr.pageObjects; 导入java.util.ArrayList; 导入java.util.HashSet; 导入java.util.LinkedList; 导入java.util.List; 导入

我收到一个StaleElementReferenceException,但我不知道为什么?爬虫程序工作正常,并在排队的URL中循环,但由于StaleElementReferenceException错误而失败

任何帮助都将不胜感激

下面是代码和错误

代码

package com.crawlerr.pageObjects;
导入java.util.ArrayList;
导入java.util.HashSet;
导入java.util.LinkedList;
导入java.util.List;
导入java.util.Queue;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入com.crawler.common.ExcelUtils;
导入com.crawler.common.System_常量;
公共类爬虫器4扩展了基类
{
public static HashSet alreadyListed=new HashSet();
public static Queue=new LinkedList();
公共爬虫4(WebDriver){
超级司机;
}
公共静态void Execute(int iTestCaseRow)引发异常{
爬网(ExcelUtils.getCellData(iTestCaseRow,System_Constants.Col_BaseURL),iTestCaseRow);
//System.out.println(“存储的”+Arrays.toString(alreadyListed.toArray());
}
公共静态无效爬网(字符串起始URL,int-iTestCaseRow)
{
添加(起始URL);
字符串新地址;
而((newAddress=queue.poll())!=null)
{
processPage(新地址、起始URL、iTestCaseRow);
//在这里,您可以添加代码来对页面执行任何操作
}
}
受保护的静态void processPage(字符串url、字符串startingUrl、int-iTestCaseRow)
{
试一试{
System.out.println(“当前URL-”+URL);
获取(url);
列表爬网列表=新的ArrayList();
爬行列表=FindAllinks();
字符串href;
System.out.println(“找到的元素总数”+crawlist.size());
对于(int i=0;i
输出:

FAILED: main
org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 20.06 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'DESKTOP-PCD960U', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=42.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 164b1efc-9098-43b1-ad44-45da58b71f3c
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
    at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:149)
    at com.crawlerr.pageObjects.Crawler4.processPage(Crawler4.java:52)
    at com.crawlerr.pageObjects.Crawler4.crawl(Crawler4.java:36)
    at com.crawlerr.pageObjects.Crawler4.Execute(Crawler4.java:25)
    at com.crawler.Tests.Crawler_Test.main(Crawler_Test.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:773)
    at org.testng.TestRunner.run(TestRunner.java:623)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
    at org.testng.SuiteRunner.run(SuiteRunner.java:259)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
    at org.testng.TestNG.run(TestNG.java:1018)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'DESKTOP-PCD960U', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: driver.version: unknown
    at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9351)
    at <anonymous class>.Utils.getElementAt(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:8978)
    at <anonymous class>.WebElement.getElementAttribute(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12019)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
    at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:621)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
失败:主
org.openqa.selenium.StaleElementReferenceException:在缓存中找不到元素-可能页面在查找后已更改
命令持续时间或超时:20.06秒
有关此错误的文档,请访问:http://seleniumhq.org/exceptions/stale_element_reference.html
构建信息:版本:'2.48.2',修订版:'41bccdd',时间:'2015-10-09 19:59:12'
系统信息:主机:'DESKTOP-PCD960U',ip:'192.168.1.3',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_65'
驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver
功能[{applicationCacheEnabled=true,rotatable=false,handlesAlerts=true,databaseEnabled=true,version=42.0,platform=WINDOWS,nativeEvents=false,acceptSslCerts=true,WebStorage Enabled=true,locationContextEnabled=true,browserName=firefox,takesScreenshot=true,javascriptEnabled=true,CSSSElectorEnabled=true}]
会话ID:164b1efc-9098-43b1-ad44-45da58b71f3c
位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance(未知源)
位于sun.reflect.delegatingConstructor或AccessorImpl.newInstance(未知源)
位于java.lang.reflect.Constructor.newInstance(未知源)
位于org.openqa.selenium.remote.ErrorHandler.CreateTrowable(ErrorHandler.java:206)
位于org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
位于org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
位于org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
位于org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:149)
位于com.crawlerr.pageObjects.Crawler4.processPage(Crawler4.java:52)
位于com.crawlerr.pageObjects.Crawler4.crawl(Crawler4.java:36)
位于com.crawlerr.pageObjects.Crawler4.Execute(Crawler4.java:25)
位于com.crawler.Tests.crawler\u Test.main(crawler\u Test.java:52)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(未知源)
在sun.reflect.DelegatingMethodAccessorImpl.invoke处(未知源)
位于java.lang.reflect.Method.invoke(未知源)
位于org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
位于org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
位于org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
在org.tes
FAILED: main
org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 20.06 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'DESKTOP-PCD960U', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=42.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 164b1efc-9098-43b1-ad44-45da58b71f3c
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
    at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:149)
    at com.crawlerr.pageObjects.Crawler4.processPage(Crawler4.java:52)
    at com.crawlerr.pageObjects.Crawler4.crawl(Crawler4.java:36)
    at com.crawlerr.pageObjects.Crawler4.Execute(Crawler4.java:25)
    at com.crawler.Tests.Crawler_Test.main(Crawler_Test.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:773)
    at org.testng.TestRunner.run(TestRunner.java:623)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
    at org.testng.SuiteRunner.run(SuiteRunner.java:259)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
    at org.testng.TestNG.run(TestNG.java:1018)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'DESKTOP-PCD960U', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: driver.version: unknown
    at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9351)
    at <anonymous class>.Utils.getElementAt(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:8978)
    at <anonymous class>.WebElement.getElementAttribute(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12019)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
    at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/Craig/AppData/Local/Temp/anonymous8982667753843323416webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:621)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
try {
    href = crawlList.get(i).getAttribute("href");

    if (href != null && isAddressValid(href, startingUrl)) {
        if (!alreadyListed.contains(href)) {
            System.out.println("Added to list - " + href);
            alreadyListed.add(href);
            queue.add(href);
        } else {
            System.out.println("Already added to list - " + href);
        }
    } else {
        System.out.println("Not valid - " + href);
    }

} catch (StaleElementReferenceException e) {
    // do nothing
}