この「invisibilityOfElementLocated()」メソッドを機能させるのに問題があります。これが私が使用しているコードで、要素が約 35 秒後に消えるのを自分の目で目撃していますが、Webdriver はこれを検出せず、このコードでクラッシュし、テストをスキップします。誰かがよりうまく機能する別の方法を持っていれば幸いです。
if ( driver.findElement( By.xpath( "//div[@class='Caption']" )).isDisplayed() ) {
System.out.println("Caption is visible.");
}
WebDriverWait wait1 = new WebDriverWait( driver , 60 );
wait1.until(
ExpectedConditions.invisibilityOfElementLocated(
By.xpath( "//div[@class='Caption']" )
)
);
これが私が引き起こすエラーです:
org.openqa.selenium.TimeoutException: Timed out after 60 seconds waiting for
element to no longer be visible: By.xpath: //div[@class='Caption']
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 16:53:24'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1',
java.version: '1.6.0_31'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(
FluentWait.java:251)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:220)
at test.TaskListPage.isLoaded(TaskListPage.java:43)
at org.openqa.selenium.support.ui.SlowLoadableComponent.get(
SlowLoadableComponent.java:48)
at test.TaskListPage.<init>(TaskListPage.java:31)
at test.Form.testLogin(Form.java:153)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(
ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(
InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunAfters.evaluate(
RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
また、このメソッドでも同様のエラーが発生します。
ExpectedCondition<Boolean> e = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
WebElement tE = driver.findElement( By.className("Caption") );
// return the invisibility instead of the visibility
return !tE.isDisplayed();
}
};
WebDriverWait w = new WebDriverWait(driver, 60);
w.until(e);
これである程度成功しましたが、要素が最終的に非表示になり、テストケースから跳ね返ると例外がスローされます。
while (
// dialogMiddleCenterInner is a td that contains the Caption div
driver.findElement( By.className("dialogMiddleCenterInner")
).isDisplayed() ) {
System.out.println("Caption is visible. Waiting for login.");
AFormUtils.waitSeconds(2);
}