[Selenium] Selenium RC二次开发遇到的问题

本文介绍了在Selenium RC二次开发中遇到的问题,包括CSS选择器a:nth-of-type(1)与a:nth-child(1)的差异,JsonNode的path()与get()方法的使用,页面等待的实现方式,以及Selenium Grid的配置和命令行运行示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. a:nth-of-type(1)和a:nth-child(1)的区别:

前者无视类型,只要是a下面的子元素,即一一列出,而后者列出的子元素类型一致。但两者相同点都是前一个元素必须唯一。

 

2. JsonNode中 path() 和 get() 的区别:

private static String getJsonValue(JsonNode nodesToSearch, String fieldName) {

 JsonNode targetNode = nodesToSearch.path(fieldName);
 return StringUtils.defaultIfBlank(targetNode.textValue(), null);
 
}

 nodesToSearch.path(fieldName);找不到时返回targetNode = missingNode,可用targetNode.isMissingNode() == true判断, targetNode.textValue() == null。
 nodesToSearch.get(fieldName);找不到时返回NULL。

 

3. 页面等待代码

waitForCondition("selenium.browserbot.getUserWindow().$.active == 0;", pageTimeout);
waitForCondition("(selenium.browserbot.getCurrentWindow().document.readyState=='interactive') || " + "(selenium.browserbot.getCurrentWindow().document.readyState=='complete');", pageTimeout);

 

4. Selenium Grid

CMD:

java -jar selenium-server-standalone-2.39.0.jar  -role  node  -hub http://10.10.55.55:3737/grid/register -port 6666

 

Maven:
<configuration>
 <testFailureIgnore>true</testFailureIgnore>
 <failIfNoTests>false</failIfNoTests>
 <forkCount>1</forkCount>
 <resuseForks>false</resuseForks>
 <argLine>-Dfile.encoding=UTF-8</argLine>
 <systemProperties>
  <property>
   <name>net.sourceforge.cobertura.datafile</name>
   <value>target/cobertura/cobertura.ser</value>
  </property>
 </systemProperties>
</configuration>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值