2016-07-14 10 views
0

私はこのようなテーブルのレイアウトを持っている:ページの繰り返しボタンをクリックする方法は?

<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を知っているだけで、適切な第2のtd(ボタン)をクリックする必要はありますか?たとえば、動的に2を取得し、最初のものではなく2番目の「Click me」ボタンをクリックすることができますか?

答えて

0

あなたはXPathを必要とする:はい方法はあり

twoClickMeButton = driver.find_element(:xpath,"//td[text()='2']/../td/button") 
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. 
関連する問題