我还在学习xpath,我试图跳过表的第一行,因为第一行没有值。我没有成功,我通过堆栈搜索流量,找不到任何有类似问题的人。我的代码如下:
int reqIndex = 0;
do {
List<WebElement> payDates = driver.findElements(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')]/td[contains(@id,'_cell_4')/span]"));
System.out.println(payDates);
for(WebElement pd:payDates) {
LocalDate localDate = LocalDate.now();
java.util.Date d = new SimpleDateFormat("yyyy-MM-dd").parse(localDate.toString());
String str = pd.getText();
if ( str >= (d) ){ // still figuring this out
driver.findElement(By.xpath( "//tr[@id='changeStartWeekGrid_row_'" + reqIndex +"])/TBODY[@id='changeStartWeekGrid_rows_tbody']/TR[7]/TD[1]/DIV[1]/DIV[1]/DIV[1]")).click();
break;
}else{
reqIndex++;
}
}
}while(reqIndex < 7 ); /// do this 7 times
Thread.sleep(10000);
这是我现在拍摄麻烦的部分
List<WebElement> payDates = driver.findElements(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')]/td[contains(@id,'_cell_4')/span]"));
System.out.println(payDates);
Thread.sleep(10000);
xpath工作的问题是它正在选择第一行并且它没有值零行,所以它需要跳过第一行并转到第0行。 当我运行代码时,我收到此消息:
( //tr[starts-with(@id,'changeStartWeekGrid_row_')]/td[contains(@id,'_cell_4')/span])
ilter expression must evaluate to nodeset.
cell 4 image
-----下面的单选按钮html代码
<div id="changeStartWeekGrid.store.rows[5].cells[0]_widget" tabindex="0" class="revitRadioButton dijitRadio" onfocus="var registry = require('dijit/registry'); registry.byId('changeStartWeekGrid').changeActiveCell('changeStartWeekGrid_row_5_cell_0', event);" onblur="var registry = require('dijit/registry'); registry.byId('changeStartWeekGrid').blurActiveCell('changeStartWeekGrid.store.rows[5]', 'changeStartWeekGrid.store.rows[5].cells[0]');"><div class="revitRadioButtonIcon"></div></div>
---单选按钮图片
答案 0 :(得分:2)
尝试使用XPath
//table[@id='changeStartWeekGrid_rows_table']//tr[preceding-sibling::tr]
选择除第一个之外的所有tr
个节点
您也可以使用position()
,如下所示:
//table[@id='changeStartWeekGrid_rows_table']//tr[position()>1]
请注意,在XPath中,索引从1
开始,因此[position()>1]
谓词意味着返回所有同级节点,滑动第一个
答案 1 :(得分:1)
您也可以使用
//tr[starts-with(@id,'changeStartWeekGrid_row_') and not(starts-with(@id, 'changeStartWeekGrid_row_column'))]/td[5]/span