我尝试将所有这些按钮添加到列表然后单击它们,我不明白如何通过cssSelector添加子项。
<md-toolbar class="md-tall md-default-theme" hide-sm=""></md-toolbar>
<md-card class="card-only-large md-default-theme" layout="column">
<!--
uiView: header
-->
<div class="ng-scope" ui-view="header"></div>
<!--
uiView: content
-->
<div class="ng-scope" flex="" layout="column" ui-view="content">
<md-content class="ng-scope md-default-theme">
<!--
phone layout start
-->
<div class="text-center" hide-gt-sm=""></div>
<!--
phone layout end
-->
<!--
tablet layout start
-->
<div class="tutor-schedule-tablet" hide-sm="">
<h3></h3>
<div class="schedule-day-navigation md-toolbar-tools" layout="row"></div>
<table class="tutor-schedule tutor-schedule-week" cellspacing="1">
<thead></thead>
<tbody>
<!--
ngRepeat: timeinterval in weekintervals[0].timeIn…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals"></tr>
<!--
end ngRepeat: timeinterval in weekintervals[0].ti…
-->
<tr class="ng-scope" ng-init="sectionIndex = $index" ng-repeat="timeinterval in weekintervals[0].timeIntervals">
<td id="timeintrval_10pm" class="timeinterval-name text-center ng-binding" scroll-if="timeinterval.name == '12pm'"></td>
<!--
ngRepeat: weekinterval in weekintervals
-->
<td class="ng-scope" ng-repeat="weekinterval in weekintervals">
<!--
{{weekinterval.timeIntervals[$parent.$index].name}…
-->
<!--
ngIf: weekinterval.timeIntervals[sectionIndex].di…
-->
<!--
ngIf: !weekinterval.timeIntervals[sectionIndex].d…
-->
<!--
ngIf: !weekinterval.timeIntervals[sectionIndex].d…
-->
<button class="md-primary md-button ng-scope" ng-if="!weekinterval.timeIntervals[sectionIndex].disabled && !weekinterval.timeIntervals[sectionIndex].isPastDate" ng-click="itemClicked_Weekly(weekinterval.timeIntervals[sectionIndex])" ng-class="{ 'timeinterval-selected' : weekinterval.timeIntervals[secti…led' : weekinterval.timeIntervals[sectionIndex].isPastDate }" tabindex="0"></button>
按钮似乎在表格中。
到目前为止,这是我的代码。
WebElement parent = driver.findElement(By.cssSelector("table.tutor-schedule:nth-child(3)"));
List<WebElement> children = parent.findElements(By.cssSelector(".md-primary .md-button"));
for (int i = 0; i < children.size(); i++) { children.get(i).click(); }
谢谢,我正在使用Java BTW。
答案 0 :(得分:2)
使用这些选择器
解决了这个问题 WebElement parent = driver.findElement(By.cssSelector(".tutor-schedule-tablet"));
List<WebElement> children = parent.findElements(By.cssSelector("button.md-primary.md-button.ng-scope"));
System.out.print("\n" + children);
for (int i = 0; i < children.size(); i++) { children.get(i).click(); }