gpt4 book ai didi

java - 为什么 Selenium Server 找不到定位器

转载 作者:行者123 更新时间:2023-12-01 04:54:05 24 4
gpt4 key购买 nike

我没有通过 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()

我的项目中的导入列表: enter image description here

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com