如何点击页面上的重复按钮?

时间:2016-07-14 23:45:45

标签: ruby selenium selenium-webdriver

我有一个像这样的表格布局:

 <tbody>
    <tr>
      <td> 1 </td>
      <td> <button> Click me </button>
    </tr>
     <tr>
      <td> 2 </td>
      <td> <button> Click me </button>
    </tr>
    ....
  </tbody>

我只知道第一个td(1,2等)的值。无论如何,只有在知道第一个td的同时点击相应的第二个td(按钮)?例如,我可以动态获得2并知道点击第二个&#34;点击我&#34;按钮而不是第一个?

2 个答案:

答案 0 :(得分:1)

是的,有道路:

基本上,您要点击的buttons兄弟姐妹到您已知的td元素。

请尝试使用xpath兄弟定位元素来找到这些按钮:

//td[contains(text(),'1')]/following-sibling::*  //this reads, first locate an element of td type whose text() attribute contains '1', then find its immediate sibling.

//td[contains(text(),'2')]/following-sibling::*  //this reads, first locate an element of td type whose text() attribute contains '2', then find its immediate sibling.

答案 1 :(得分:0)

你需要一个XPath:

twoClickMeButton  = driver.find_element(:xpath,"//td[text()='2']/../td/button")
相关问题