我有以下html,希望选择(点击)td
class
和tree-label-name ng-binding
text()
Approver
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<treecontrol tree-model="vm.homeStats" expand-level="0" on-selection="vm.selectStatsNode(node)" on-node-toggle="vm.toggleTreeNode(node, expanded)" expanded-nodes="vm.expandedNodes" selected-node="vm.selectedNode" class="ng-isolate-scope">
<ul class="ng-scope">
<li ng-repeat="node in node.children | filter:filterExpression:filterComparator" ng-class="headClass(node)" class="ng-scope tree-collapsed tree-selected">
<i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node)"></i><i class="tree-leaf-head "></i>
<div class="tree-label tree-selected" ng-class="selectedClass()" ng-click="selectNodeLabel(node)" tree-transclude="">
<table class="ng-scope">
<tbody>
<tr>
<td class="tree-label-icon"><img bf-image-path="user" class="tree-icon" src="/Assets/img/icons/user.png"></td>
<td class="tree-label-name ng-binding">
Strydom, AJ (Rico)<br>
<progress-bar ng-if="::!node.isFolder" value="6" max-value="230" class="ng-scope">
<div class="progress-bar" ng-style="barStyles">
<div class="progress-bar-value" ng-style="valueStyles" style="width: 2.6087%;"></div>
</div>
</progress-bar>
</td>
<td width="30" class="text-right">
<strong class="process-bar-total ng-binding ng-scope" ng-if="::!node.isFolder">6</strong><!-- end ngIf: ::!node.isFolder -->
</td>
</tr>
</tbody>
</table>
</div>
</li>
<li ng-repeat="node in node.children | filter:filterExpression:filterComparator" ng-class="headClass(node)" class="ng-scope tree-collapsed">
<i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node)"></i><i class="tree-leaf-head "></i>
<div class="tree-label " ng-class="selectedClass()" ng-click="selectNodeLabel(node)" tree-transclude="">
<table class="ng-scope">
<tbody>
<tr>
<td class="tree-label-icon"><img bf-image-path="team" class="tree-icon" src="/Assets/img/icons/team.png"></td>
<td class="tree-label-name ng-binding">
Approver<br>
<progress-bar ng-if="::!node.isFolder" value="1" max-value="230" class="ng-scope">
<div class="progress-bar" ng-style="barStyles">
<div class="progress-bar-value" ng-style="valueStyles" style="width: 0.434783%;"></div>
</div>
</progress-bar>
</td>
<td width="30" class="text-right">
<strong class="process-bar-total ng-binding ng-scope" ng-if="::!node.isFolder">1</strong><!-- end ngIf: ::!node.isFolder -->
</td>
</tr>
</tbody>
</table>
</div>
</li>
<li ng-repeat="node in node.children | filter:filterExpression:filterComparator" ng-class="headClass(node)" class="ng-scope tree-collapsed">
<i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node)"></i><i class="tree-leaf-head "></i>
<div class="tree-label " ng-class="selectedClass()" ng-click="selectNodeLabel(node)" tree-transclude="">
<table class="ng-scope">
<tbody>
<tr>
<td class="tree-label-icon"><img bf-image-path="team" class="tree-icon" src="/Assets/img/icons/team.png"></td>
<td class="tree-label-name ng-binding">
Assigner<br>
<progress-bar ng-if="::!node.isFolder" value="230" max-value="230" class="ng-scope">
<div class="progress-bar" ng-style="barStyles">
<div class="progress-bar-value" ng-style="valueStyles" style="width: 100%;"></div>
</div>
</progress-bar>
</td>
<td width="30" class="text-right">
<strong class="process-bar-total ng-binding ng-scope" ng-if="::!node.isFolder">230</strong><!-- end ngIf: ::!node.isFolder -->
</td>
</tr>
</tbody>
</table>
</div>
</li>
</ul>
</treecontrol>
这是我的代码,似乎没有执行点击操作。
WebElement inboxTypeToSelect = webdriver.findElement(By.xpath("//treecontrol[@class='ng-isolate-scope']/ul/li/div/table/tbody/tr/td[@class='tree-label-name ng-binding' and normalize-space(text() = '" + inboxType + "')]"));
Actions action = new Actions(webdriver);
action.click(inboxTypeToSelect);
action.perform();
传递给inboxType
的值为Approver
,因此xpath为:
//treecontrol[@class='ng-isolate-scope']/ul/li/div/table/tbody/tr/td[@class='tree-label-name ng-binding' and normalize-space(text() = 'Approver')]
知道为什么不采取行动?
答案 0 :(得分:1)
尝试以下xpath:
//tr/td[contains(text(),"Approver")]
尝试如下:
WebElement inboxTypeToSelect = webdriver.findElement(By.xpath("//tr/td[contains(text(),"Approver")]"));
Actions action = new Actions(webdriver);
action.click(inboxTypeToSelect).perform();
点击方法后调用perform()。
而不是动作链使用点击WebElement本身。
WebElement inboxTypeToSelect = webdriver.findElement(By.xpath("//tr/td[contains(text(),"Approver")]"));
inboxTypeToSelect.click();
答案 1 :(得分:0)
你可以通过xpath找到合适的批准者:
的HTML /体/树形控件/ UL /锂[2] / DIV /表/ tbody的/ TR / TD [2]
driver.findElement(By.xpath("html/body/treecontrol/ul/li[2]/div/table/tbody/tr/td[2]")).click();