【发布时间】:2017-05-04 18:03:16
【问题描述】:
我有一个 4 行 4 列的表格。最后两列有两个按钮:开始和取消。我想为第二行/最后一列按下取消按钮。每一行的代码都是相似的......减去我要启动的服务名称。
<table class="table">
<tbody>
---this is the first row---
<tr ng-repeat="toyService in theService" ng-class="{'text-muted':toyservice.notFound" class="ng-scope">
--- this is the second row.. the row I am trying to start----
<tr ng-repeat="toyService in theService" ng-class="{'text-muted':toyservice.notFound" class="ng-scope">
<td style="text-align:center">...</td>
<td class="ng-binding"> Toy Service 2 </td>
<td class="ng-binding">...</td>
<td class="toy-service-button-panel text-right">
----the first button (Start Button)
<button type="submit" class="btn btn-info">...</button>
----the button I am trying the click (Cancel)
<button type="submit" class="btn btn-success btn-sm"
<span title="Cancel Service">..</span>
每一行都有相同的代码减去服务名称:
第 1 行 玩具服务 1
第 2 行 玩具服务 2
第 3 行 Toy Service 3
第 4 行 玩具服务 4
我尝试的是:
driver.find_element_by_xpath("//td[contains(text(), 'Toy Service 2')]/follow-sibling::td").find_element_by_css_selector("td[class='toy-service-button-panel.text-right']").find_element_by_css_selector("button[class='btn.btn-success.btn-sm']").click()
我收到一条错误提示
无法执行'评估'文档:字符串 //td[contains(text(), Toy Service 1')]/follow-sibling::td' 不是 有效的 XPath 表达式。
我尝试了不同的方法,但我似乎无法单击第 2 行的取消按钮
【问题讨论】:
标签: python css xpath css-selectors siblings