0

私はこの方法を使って読んでいます

FileInputStream fi = new FileInputStream("C:\\Users\\GChaitanya.CHAINGANG\\Desktop\\2012_October_3PL_Unified_Template.xls");
Workbook w = Workbook.getWorkbook(fi);
s = w.getSheet(0);

そして、これを書く

WritableWorkbook wb = Workbook.createWorkbook(new File("D:\\output_2.xls"));
WritableSheet ws = wb.createSheet("customsheet", 1);

このエラーが発生します

org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 100.10 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Session ID: 60c039f3-60bb-413f-aca5-0543e074b04e
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=24.0}]
    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:191)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
    at gmailTest.TestLink.RealTime(TestLink.java:100)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
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.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: unknown
    at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web_element_cache.js:7642)
    at <anonymous class>.Utils.getElementAt(file:///C:/Users/GCHAIT~1.CHA/AppData/Local/Temp/anonymous5288729173687770784webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:7231)
    at <anonymous class>.fxdriver.preconditions.visible(file:///C:/Users/GCHAIT~1.CHA/AppData/Local/Temp/anonymous5288729173687770784webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:8228)
    at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/GCHAIT~1.CHA/AppData/Local/Temp/anonymous5288729173687770784webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10799)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/GCHAIT~1.CHA/AppData/Local/Temp/anonymous5288729173687770784webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10816)
    at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/GCHAIT~1.CHA/AppData/Local/Temp/anonymous5288729173687770784webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:396)

これをデバッグモードで表示します

<terminated, exit value: 0>C:\Program Files\Java\jre7\bin\javaw.exe (Oct 29, 2013 5:12:25 PM)   

コードは正常に動作していましたが、突然動作を停止し、10 レコードをほとんど読み取らず、クラッシュしました。少なくとも 300 ~ 400 件のレコードを読み取ることができました

4

2 に答える 2

0

これは、Excel ファイルの読み取りまたは書き込みに関するエラーではありません。次の行で Selenium を使用して Web 要素をクリックすると、エラー (StaleElementReferenceException) が発生します。

gmailTest.TestLink.RealTime (TestLink.java:100) で

Web 要素をクリックする前に、要素に有効な最新の参照があることを確認してください。

StaleElementReferenceException http://docs.seleniumhq.org/exceptions/stale_element_reference.jspについて参照してください。

于 2013-11-12T11:48:30.763 に答える
0
package realDatatesting;
import java.io.FileInputStream;
import java.util.concurrent.TimeUnit;
//import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
//import org.openqa.selenium.remote.RemoteWebDriver;
//import com.google.common.collect.Table.Cell;
public class Realtime_snap{
Sheet s;
WebDriver driver;
@Before
public void setUp()
{
 driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
}
/**
* @throws Exception
*/
@Test
public void RealTime() throws Exception
{

driver.get("----URl---");

//Passing the user name and password
driver.findElement(By.id("-----")).sendKeys("-----");
driver.findElement(By.id("-------")).sendKeys("------");
//Clicking on login button
driver.findElement(By.id("-------")).click();

//Selecting real time estimator
driver.findElement(By.xpath(".//*[@id='nav']/li[3]/a")).click();
driver.findElement(By.xpath(".//*[@id='nav']/li[3]/ul/li[2]/a")).click();


//Selecting model
driver.findElement(By.xpath("----")).click();
driver.findElement(By.xpath("------")).click();

FileInputStream fi = new FileInputStream("---Filepath");
Workbook w = Workbook.getWorkbook(fi);
s = w.getSheet(0);
int totalrows=s.getRows();
for(int row=31; row < totalrows;row++)
{
    Thread.sleep(1000);
    s = w.getSheet(0);
    WritableWorkbook wb = Workbook.createWorkbook(new File("D:\\output1.xls"));
    WritableSheet ws = wb.createSheet("customsheet", 1);


    Thread.sleep(1000);
    String origin = s.getCell(1,row).getContents();
    driver.findElement(By.xpath("----")).sendKeys(origin);

    .
            .
            .
    String TempCont = s.getCell(13,row).getContents();
    driver.findElement(By.xpath("------")).sendKeys(TempCont);

    //Click's on calculate button
    driver.findElement(By.xpath("------")).click();
    Thread.sleep(1000);



        String m1 = (driver.findElement(By.id("------")).getText());
        Label label1 = new Label(1, row, m1);
        ws.addCell(label1);

      .
      .
      .

        String m17 = (driver.findElement(By.id("ctl00_ContentPlaceHolderBody_ucModelDataEntry1_lblRegionalVariability")).getText());
        Label Label17 = new Label(18, row, m17);
        ws.addCell(Label17);
      //Click on Reset
    driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolderBody_ucModelDataEntry1_resetBtn']")).click();
    Thread.sleep(1000);

    //Clicking on logout

     wb.write();                                                            

        wb.close();

}

} 



@After
public void tearDown() throws InterruptedException
{
Thread.sleep(10000);        
driver.findElement(By.xpath(".-----")).click();
driver.close();
driver.quit();
}
}

これは正常に機能していたコード全体で、何がうまくいかなかったのかわかりませんが、多くの方法を試しましたが、どれも機能しませんでした。

于 2013-10-30T12:13:51.983 に答える