2016-07-14 2 views
1

私は次の構造を持っています。ここでは、Test1の隣にあるボタンの2番目のゴミ箱アイコンをクリックしようとしています。Selenium python特定のテキストの隣にあるアイコンをクリックします

<tr class=“ng-scope”> 
    <td class=“ng-scope”></td> 
    <td class=“ng-scope”></td> 
    <td class=“ng-scope”> 
    <span class=“ng-binding”>Test0</span> 
    </td> 
    <td class=“ng-scope”> 
    <button class=“bin btn-xs”> 
     <i class="glyphicon glyphicon-trash"></i> 
    </button> 
    </td> 
</tr> 
<tr class=“ng-scope”> 
    <td class=“ng-scope”></td> 
    <td class=“ng-scope”></td> 
    <td class=“ng-scope”> 
    <span class=“ng-binding”>Test1</span> 
    </td> 
    <td class=“ng-scope”> 
    <button class=“bin btn-xs”> 
     <i class="glyphicon glyphicon-trash"></i> 
    </button> 
    </td> 
</tr> 

は、現在、私が実装していますどのようにxpathが//[email protected]="glyphicon glyphicon-trash"で、インデックスが与えられた結果で検索んfind_element_by_xpathを行うことです。 しかし、これは非効率的な終了を見つける、特に与えられた結果は理論的に多くのことができ、私は結果リストをループする必要があります。

私はまた、次の行を試してみました:ごみ箱のアイコンは、実際のTest1の兄弟ではないので

動作しません
myxpath = "//*[contains(text(), 'Test1')]/following-sibling::tr/button[@class='glyphicon glyphicon-trash']" 
driver.find_by_xpath(myxpath) 

を(

どのように私はより良い方法(IEでこれを実装することができます。私はTest1をアンカーとして使用し、その横にあるゴミ箱のボタンをTest0の隣ではなくクリックしたいと思っていますか?

+0

を一度 '//スパン[テキスト()=「Test1を」] /以下:: button'を試してみて、私に知らせて... –

+0

@SaurabhGaurいいえ、動作しません。 – heike

答えて

0

テキストを有する行のボタンを選択するには:

//tr[.//text()='Test1']//button 

セル3内のテキストを有する行のセル4のボタンを選択するには:

//tr[td[3]//text()='Test1']/td[4]//button 

セルを選択します以下のセル内のテキストと、ボタン持つ:

//td[.//text()='Test1']/following-sibling::td[1]//button" 
0

ボタンやアイコンが必要かどうかはわかりません... ここはiタグです

もその

//i[@class='glyphicon glyphicon-trash' and ../../../td/span/text() = "Test1"] 

を試してみてくださいpsのノート:

<span class="ng-binding"> Test1 </span> 

は異なっています。

+0

テキストの前後にスペースがないため、説明を更新します – heike

関連する問題