- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Selenium (2.44.0) 进行 Java 单元测试,并且我正在尝试使用 WebElement的 isDisplayed()
方法,但它似乎不可用。我只能看到 isEnabled()
和 isSelected()
方法。
(Eclipse 中的错误消息:“WebElement 类型的方法 isDisplayed() 未定义”)
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.499</version>
<!-- which version of Hudson is this plugin built against? -->
<relativePath />
</parent>
<artifactId>extended-choice-parameter</artifactId>
<packaging>hpi</packaging>
<version>0.35-SNAPSHOT</version>
<name>Extended Choice Parameter Plug-In</name>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin</url>
<developers>
<developer>
<id>vimil</id>
<name>Vimil Saju</name>
</developer>
</developers>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>InjectedTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.15</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-common</artifactId>
<version>2.0b1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- get every artifact through maven.glassfish.org, which proxies all the artifacts that we need -->
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>http://maven.jenkins-ci.org/content/repositories/releases/</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:git:ssh://git@github.com/jenkinsci/extended-choice-parameter-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/extended-choice-parameter-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/extended-choice-parameter-plugin</url>
</scm>
Java代码:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
.......
WebElement element;
int size = driver.findElements(By.xpath("//select[@name='type']")).size();
for (int i = 0; i < size; i++) {
element = driver.findElements(By.xpath("//select[@name='type']")).get(i);
if (element.isDisplayed()) {
select = new Select(element);
select.selectByVisibleText("Multi-Level Multi Select");
break;
}
}
知道我可能会错过什么吗?
编辑 - 添加了完整的 pom.xml 和 eclipse 错误消息以澄清问题
编辑 (2) - 将 Java 代码更改为有关 @Vivek Singh 关于异常处理的第一个评论的实际(已使用)Java 代码
最佳答案
Selenium commons 在完全相同的包结构中引入了 WebElement.java,但没有 isDisplayed() 方法。所以你的引用资料被搞乱了。不要在 pom.xml 中包含 selenium-commons
关于Java - Selenium WebElement isDisplayed() 方法不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28435691/
有什么区别 1.ViewInteraction v = onView(allOf(withId(R.id.login_card_view), isDisplayed())) 和 2.v.check(匹
我正在开发 Java Selenium 项目,并使用 isDisplayed() 方法来验证某些元素是否显示在页面上,并且每个方法的执行大约需要 45 秒,是有什么建议为什么可能需要这么长时间,可以在
WebElement.isDisplayed() 方法搜索元素可见性所需的最长时间是多少? 我们可以在不使用隐式等待的情况下定义时间吗? 最佳答案 isDisplayed() 方法是立即执行的,您无法
我正在使用 Selenium 来测试输入字段为空时错误消息的外观。错误消息设计为输入元素的标签。当消息不可见时,它具有属性“display: none;”。 当我通过文本找到该消息并调用 isDisp
我只是自动化测试的初学者。只会c、c++和PHP。现在我想通过自动化测试来学习 Java。 我想检查该元素是否存在以及它是否可见,我在此页面上找到了解释,为了检查它是否可见我必须使用 .isDispl
我正在使用 Selenium 来检查当用户发送带有空字段的表单时是否显示错误消息。错误消息 block 始终附加到 DOM,但是当没有错误时,它会显示“display: none;”样式属性。因此,当
我正在尝试测试 UI View 的缺失。 View 选择器如下: public static ViewInteraction onMyTestUi() { return onView(with
我正在使用 Selenium (2.44.0) 进行 Java 单元测试,并且我正在尝试使用 WebElement的 isDisplayed() 方法,但它似乎不可用。我只能看到 isEnabled(
我想单击后退按钮,直到到达应用程序中的特定页面(我的 expectedElement 所在的页面)。这似乎不起作用... 它失败了,因为它找不到预期的元素。 function navigateBack
我刚开始使用 Protractor 编写测试。我想知道 isPresent() 和 isDisplayed() 方法之间有什么区别。 API 定义 isPresent isDisplayed 那么..
假设您正在使用 API,您需要设置一个值来启用或禁用组件。 你愿意: control.isEnable = true 或 control.isDisable = false Imo,第一个似乎更“直观
目前,我在很多情况下都需要验证页面(及其所有元素)是否正确显示。 WebElement 的 isDisplayed() 方法似乎是执行此操作的逻辑方法,但是我想准确了解该方法正在做什么来确定元素是否“
我正在创建一个脚本,其中涉及搜索记录然后更新记录。在搜索屏幕上,用户可以选择查看高级搜索选项。通过一个按钮即可控制显示或隐藏高级搜索。 显示或隐藏高级搜索时搜索按钮的属性之间的唯一区别是 img s
我需要检查页面上元素的可见性。 我正在使用 (psuedocode) wait.until(ExpectedCondition.visibilityOfElement(locator)); 但是,默认
这将是一个很长的问题:p 尽管我在 element.isPresent 和 element.isDisplayed 上进行了显式等待并等待每个 promise 得到解决,但基本上消除了任何异步性,但我
我正在尝试编写一个 while 循环来检查加载元素的 isDisplayed() 属性,如果加载窗口可见则打印“它正在加载”。如果加载窗口消失,则 while 循环将退出。 private By su
我有一些 E2E 测试目前正在通过。我认为这按预期工作,但是当我在将数据输入字段后使用 browser.sleep() 修改某些字段以查看测试是否会在达到预期结果时失败。 我们的测试规范填写了一个表单
传统上,我总是使用以下方法检查 appium 中是否存在对象: int count = driver.findElements(by).size(); if (coun
isDisplayed 和 withEffectiveVisibility 有什么区别? onView(withText("Much Dagger")).check(matches(withEffec
Component.isShowing() 之间有什么区别?和 Component.isDisplayable() ?我想用它们来决定我是否应该停止/启动计时器。 最佳答案 一个组件 isShowin
我是一名优秀的程序员,十分优秀!