java - 添加多个元素到列表并单击 cssSelector WebDriver Java

标签 java selenium webdriver

我试图将所有这些按钮添加到列表中,然后单击它们,我不明白如何通过 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。

最佳答案

使用这些选择器解决了这个问题

 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(); }     

关于java - 添加多个元素到列表并单击 cssSelector WebDriver Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29608324/

相关文章:

java - 如何在 Java 环境中解码 H.264 视频帧

javax.el.MethodNotFoundException : Method not found: JSP

perl - 加速 Selenium Webdriver

linux - (Watir-)Webdriver 在 Fedora 14 w/Firefox 10 上找不到稳定的 Firefox 连接

selenium - 无效参数异常 : invalid argument: Unsupported locator strategy: -custom error with Appium using Selenium ChromeDriver and Chrome

java - 为什么按一次鼠标会调用 Java MousePressed 两次?

java - Java中使用Scanner读取整行字符串

java - 即使我在正确的域中,Selenium addCookie 也会出现无效的 Cookie 域异常

java - Selenium Webdriver submit() 与 click()

selenium - 如何在 Linux 平台的 selenium 中实现 chromedriver