1

我没有通过 Eclipse / Java / Selenium Server 2 找到定位器

Object el = findElement( "//table[@id='global_list']//tr//td[2]//a[text()='mytext']" );
//==> return null
String deb = findElement( "//table[@id='global_list']//tr//td[2]" ).getText();
//==> return 'mytext'

我通过 FireFox 上的 firepath 扩展找到了定位器成功。我究竟做错了什么?

4

1 回答 1

0
driver.findElement(By.xpath("//table[@id='global_list']//tr//td[2]" )).click()

尝试这个

String textElem=driver.findElement(By.xpath("//table[@id='global_list']//tr//td[2]" )).getText()

或这个

driver.findElement(By.xpath("//*/a[contains(text(),'blablabla')])").click()

我的项目中的进口清单: 在此处输入图像描述

POM.xml 中的依赖项列表

 <dependencies>
<!--
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
-->
      <dependency> <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>2.24.1</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>3.0.0.RELEASE</version>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-expression</artifactId>
          <version>3.0.0.RELEASE</version>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>3.0.0.RELEASE</version>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>3.0.0.RELEASE</version>
      </dependency>

      <!--<dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.4</version>
          <scope>test</scope>
      </dependency>
-->
      <dependency>
          <groupId> org.apache.cassandra</groupId>
          <artifactId>cassandra-all</artifactId>
          <version>0.8.1</version>
      </dependency>

      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.6.6</version>
      </dependency>
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>1.6.6</version>
          <scope>runtime</scope>
      </dependency>
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jul-to-slf4j</artifactId>
          <version>1.6.6</version>
          <scope>runtime</scope>
      </dependency>
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>log4j-over-slf4j</artifactId>
          <version>1.6.6</version>
          <scope>runtime</scope>
      </dependency>
      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.2</version>
      </dependency>

  </dependencies>

希望现在这对你有用

于 2013-01-22T16:04:14.303 回答