Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-Selenium WebElement isDisplayed()方法不可用_Java_Maven_Selenium_Selenium Webdriver - Fatal编程技术网

Java-Selenium WebElement isDisplayed()方法不可用

Java-Selenium WebElement isDisplayed()方法不可用,java,maven,selenium,selenium-webdriver,Java,Maven,Selenium,Selenium Webdriver,我正在使用Selenium(2.44.0)进行Java单元测试,并尝试使用的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

我正在使用Selenium(2.44.0)进行Java单元测试,并尝试使用的
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>

4.0.0
org.jenkins-ci.plugins
插件
1.499
扩展选择参数
hpi
0.35-1
扩展选择参数插件
http://wiki.jenkins-ci.org/display/JENKINS/Extended+选择+参数+插件
维米尔
维米尔萨朱
org.apache.maven.plugins
maven surefire插件
InjectedTest.java
测试
测试
net.sf.opencsv
opencsv
2
朱尼特
青年部
4.8.2
测试
net.sourceforge.htmlunit
htmlunit
2.15
测试
org.mockito
莫基托所有
1.8.0
测试
org.hamcrest
汉克雷斯特岩芯
1.3
编译
org.seleniumhq.selenium
硒爪哇
2.44.0
org.seleniumhq.selenium
硒铬驱动器
2.5.0
org.seleniumhq.selenium
普通硒
2.0b1
org.seleniumhq.selenium
硒原料药
2.44.0
org.testng
testng
6.1.1
测试
repo.jenkins-ci.org
http://repo.jenkins-ci.org/public/
repo.jenkins-ci.org
http://repo.jenkins-ci.org/public/
maven.jenkins-ci.org
http://maven.jenkins-ci.org/content/repositories/releases/
scm:git:ssh://git@github.com/jenkinsci/extended-choice-parameter-plugin.git
scm:git:ssh://git@github.com/jenkinsci/extended-choice-parameter-plugin.git
https://github.com/jenkinsci/extended-choice-parameter-plugin

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;
        }
    }
import org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.support.ui.Select;
.......
网络元素;
int size=driver.findElements(By.xpath(//select[@name='type'])).size();
对于(int i=0;i
知道我遗漏了什么吗

编辑-添加完整的pom.xml和eclipse错误消息以澄清问题


编辑(2)-将@Vivek Singh关于异常处理的第一条评论的Java代码更改为实际(使用过的)Java代码

这与@tome所说的一模一样。selenium-common.jar是2.0b1版<代码>isDisplayed()
已添加到Selenium 2.0(最终版)中。在此之前,它被定位在其他类别。因此
selenium common
屏蔽
selenium api
,这就是您无法编译的原因。

selenium commons以完全相同的包结构引入WebElement.java,但没有isDisplayed()方法。所以你的推荐信搞砸了。不要在pom.xml中包含selenium commons,因为我不知道这里发生了什么。但是出于好奇,如果找不到元素,findElement不会抛出异常吗?那么在这种情况下,显示的不是一条无法到达的线路吗?欢迎对此发表任何意见。selenium-api.jar的版本是什么?能否请您使用maven强制更新您的项目?或者清理并重新构建它?对硒的依赖很普遍(很多)。只需删除除selenium java之外的所有selenium依赖项即可。@lkisac发生此错误的原因是您没有guava依赖项。该错误与selenium无关。我建议您添加服务器和guava依赖项,删除rest selenium依赖项,并强制更新或清理项目。根据我使用selenium 2.44.0和commons lang 3.x的经验,我对它没有任何问题。它很好用。