我对硒有一些问题。
我想将一些String content
发送到我网站上的ID =“source”的元素并提交
这是我的代码
driver.get("http://hiriji.com/");
WebElement viet = driver.findElement(By.id("source"));
viet.sendKeys(content);
viet.submit();
效果很好,直到内容太大。
后
viet.sendKeys(content);
网页突然变为404错误页面。 所以它在
时出错了viet.submit();
我的问题是如何忽略此错误并继续下面的代码。 我不需要将所有内容发送到网络,如果它太大就可以忽略......
堆栈跟踪说:Exception in thread "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: 392 milliseconds
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'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_31'
Driver info: driver.version: RemoteWebDriver
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:498)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:244)
at org.openqa.selenium.remote.RemoteWebElement.submit(RemoteWebElement.java:81)
at RecieveData.TranslateStatus.translateViToEn(TranslateStatus.java:22)
at RecieveData.htmlParser.parseHtml(htmlParser.java:43)
at RecieveData.AddressToHtml.parseHtmlStatus(AddressToHtml.java:105)
at RecieveData.MainProcess.main(MainProcess.java:29)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element not found in the cache - perhaps the page has changed since it was looked up
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_31'
Driver info: driver.version: unknown
答案 0 :(得分:0)
只检查内容的长度。如果超出限制,请不要让表单提交。
if(content.length()<=acceptableLimit)
viet.sendKeys(content);
viet.submit();
答案 1 :(得分:0)
可能的原因:手术后
driver.get("http://hiriji.com/");
您没有获得应该在页面上加载的所有元素。
添加隐式等待driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
以验证我是对还是
driver.get("http://hiriji.com/");
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
WebElement viet = driver.findElement(By.id("source"));
viet.clear();
viet.sendKeys(content);
viet.submit();//or as alternative try to click on 'submit' button