1

页面来源:

<TABLE class=mini-listbox-items style="WIDTH: 100%" cellSpacing=0 cellPadding=0>
<TBODY>
<TR class="mini-listbox-item mini-listbox-item-selected" id=mini-45$0 index="0">
<TD class=mini-listbox-checkbox><INPUT id=mini-45$ck$0 type=checkbox CHECKED></TD>
<TD class="">xx</TD></TR>
<TR class=mini-listbox-item id=mini-45$1 index="1">
<TD class=mini-listbox-checkbox><INPUT id=mini-45$ck$1 type=checkbox></TD>
<TD class="">yy</TD></TR></TBODY></TABLE></DIV><INPUT type=hidden value=Y></DIV>
<DIV class=mini-errorIcon></DIV></DIV></DIV>
<DIV class=mini-shadow style="DISPLAY: none; Z-INDEX: 1002; LEFT: 393px; WIDTH: 78px; TOP: 326px; HEIGHT: 46px"></DIV></BODY>

我的代码:

driver.findElements(By.xpath(("//td[@class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).size();
driver.findElements(By.xpath(("//td[@class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).get(0).getText();

第一行,它打印 2,然后第二行,它不打印,为什么?

4

1 回答 1

1

Your logic is working fine.

  int n=driver.findElements(By.xpath(("//td[@class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).size();
  String s=driver.findElements(By.xpath(("//td[@class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).get(0).getText();
  System.out.println(n+"======>>"+s);

The above code is giving correct output only.

2======>>xx

于 2012-12-27T13:39:27.483 回答