我没有通过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扩展找到了定位器成功。
我究竟做错了什么?

最佳答案

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>


希望现在这对你有用

关于java - 为什么Selenium Server找不到定位器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14457100/

10-08 22:23