5

私はセレン2.2を使用しています。

最初は表示されていないが、テスト中に表示される要素をクリックしようとしています。最初は、Web ドライバーの動作が速すぎるように見えたために、要素が時間内に表示されず、ElementNotVisibleExceptions が発生することがありました。これらの要素が表示/クリック可能になるまで待機する WebDriverWait を追加しました。しかし、今では使用時にこのランダムなエラーが発生しています

WebDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id")));

同じ

WebDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("id")));

ここにスタックトレースがあります

org.openqa.selenium.WebDriverException: Error determining if element is displayed (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 219 milliseconds Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 19:03:59' System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1 build 2600 Service Pack 3', java.version: '1.6.0' Driver info: driver.version: RemoteWebDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:516) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:123) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:438) at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:280) at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:136) at org.openqa.selenium.support.ui.ExpectedConditions.access$1(ExpectedConditions.java:135) at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:106) at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:1) at org.openqa.selenium.support.ui.ExpectedConditions$11.apply(ExpectedConditions.java:252) at org.openqa.selenium.support.ui.ExpectedConditions$11.apply(ExpectedConditions.java:1) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:201) at MyTest.myTest(MyTest.java:xx) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:600) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:243) at junit.framework.TestSuite.run(TestSuite.java:238) at junit.framework.TestSuite.runTest(TestSuite.java:243) at junit.framework.TestSuite.run(TestSuite.java:238) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

これは時々しか起こりません。WebDriverException を無視すると、この問題が解決する可能性がありますが、それは完全な解決策とは思えません。タイムアウト制限を1分以上に設定しようとしたが、数ミリ秒経ってもまだ失敗するため、タイムアウトの問題になることはありません。

誰もそれに対するきれいな解決策を持っていますか?

前もって感謝します

編集:ところで。InternetExplorerDriver を使用しています

4

1 に答える 1

0

ページに modalPanel が 1 つしかないことを確認してください。可視パネルを取得してみてください(Java):

public WebElement getVisibleModalPanel(){
 for (WebElement element : driver.findElements(By.cssSelector('csslocator'))) {
  if (element.isDisplayed()) {
       return element;
  }
 }
 return null;
}

そのようなことを待つ実装:

(new WebDriverWait(getDriver(), timeout, 400)).ignoring(StaleElementReferenceException.class).until(
                new ExpectedCondition<Boolean>() {

                    @Override
                    public Boolean apply(WebDriver driver) {
                        for (WebElement element : driver.findElements(By.cssSelector(locator))) {
                            if (element.isDisplayed()) {
                                return true;
                            }
                        }
                        return false;
                    }

                });
于 2013-04-22T12:17:56.123 に答える