私は次の構造を持っています。ここでは、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の隣ではなくクリックしたいと思っていますか?
を一度 '//スパン[テキスト()=「Test1を」] /以下:: button'を試してみて、私に知らせて... –
@SaurabhGaurいいえ、動作しません。 – heike