【发布时间】:2014-12-15 01:57:13
【问题描述】:
我有一些使用 Firefox 驱动程序进行自动 UI 测试的 Selenium 代码。我将它们绑定到一个测试套件中并有序地运行它们。但它在 driver.switchTo().frame() 调用上失败并抛出 org.openqa.selenium.NoSuchFrameException: Unable to locate frame,完整的错误消息是如下:
org.openqa.selenium.NoSuchFrameException: Unable to locate frame: OpenNewPKFD
Command duration or timeout: 3.07 seconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'H3000-0254', ip: '169.254.169.127', os.name: 'Windows Vista', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_13'
Session ID: 4fcea4bb-880c-4725-bdf1-cda4b5a03553
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=32.0.3, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
奇怪的是,如果我在单步模式下运行它,抛出异常的代码行会正常工作。不会发生错误。所以我怀疑有些东西与时间或速度有关,但我根本不知道它是什么。
那么你能给我一些建议来解决这个问题吗?
已更新下面是我项目的 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>GALSelenium</groupId>
<artifactId>GALSelenium</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<selenium.version>2.43.1</selenium.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
【问题讨论】:
-
您如何找到
<iframe>元素?您是否使用 ExpectedCondition 来确保在您尝试切换到 DOM 时将其加载到 DOM 中? -
@MarkRowlands 好像没有,你能给我一些关于这个的教程或示例链接吗?
-
看看文档,selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/…,下面是一个简单的例子。
标签: java debugging firefox testing selenium