如何使用webdriver定位动态Web元素

时间:2016-08-19 07:23:09

标签: selenium

网页是使用aspx页面编写的。哪里没有固定的行和元素。哪个动态变化。

请查看附带的代码,让我知道如何构建CSS Selector路径/ Xpath以找到按钮" showAirlineCreateButton",其位置动态变化。



<div class="row">
 <div class="client_name col-xs-offset-2 col-xs-8">
   <h4 class="ng-binding">TEST </h4>
     </div>

                    <!-- ngRepeat: scheduleBasicDetail in Airline_item.scheduleBasicDetailList --><div ng-repeat="scheduleBasicDetail in Airline_item.scheduleBasicDetailList" class="ng-scope">
                        <div class="col-xs-offset-2 col-xs-8" style="height:86px;">
                        <!-- ngIf: scheduleBasicDetail.Client_ID!=0 --><div class="tri_widget widget md-whiteframe-z2 ng-scope ng-isolate-scope flex layout-column" ng-class="::{'widget-overlay-title': vm.overlayTitle}" flex="" layout="column" ng-if="scheduleBasicDetail.Client_ID!=0" title-position="top" ng-click="redirect(scheduleBasicDetail.Schedule_ID,scheduleBasicDetail.Client_ID)" title="" role="button" tabindex="0"><!-- ngIf: ::(vm.title || vm.subtitle) --><div class="widget-content layout-column layout-align-start-stretch flex-order-2" layout="column" layout-align="" ng-class="{'layout-padding': vm.contentPadding}" ng-transclude="" flex-order="2">
                            <div layout="row" layout-wrap="" class="layout-wrap ng-scope layout-row">
                                <div flex="10" class="flex-10">
                                    <img class="TESTListFirstTableTdImage" ng-src="http://10.255.109.100/TESTService/Services/../Repository/TEST/TEST/Logo.png" src="http://10.255.109.100/TESTService/Services/../Repository/TEST/TEST/Logo.png">
                                </div>
                                <div flex="80" class="Small_Padding_Left flex-80">
                                <div layout="row" class="layout-row">
                                  
                                     <div flex="33" id="title" class="ng-binding flex-33">HX-JAN17-01</div>
                                    <div flex="33" class="AirLineScheduleSystemName ng-binding flex-33">PAC eFX / PAC eX2 / Thales i5000</div>
                                    <div flex="33" class="flex-33"></div>
                                </div>
                                    <div layout="row" class="layout-row">
                                    <div flex="33" class="flex-33"><span class="TESTScheduleMonth ng-binding">January</span> <br>
                                    <span class="TESTScheduleYear ng-binding">2017</span>   
                                    </div>
                                    <div flex="66" class="flex-66"><span class="AirLineScheduleAssets ng-binding">0 Assets</span><br>
                                          <span class="TESTScheduleAssets ng-binding">MOVIES / I-MOVIES / TV / OTHERS</span>   
                                    </div>
                                   
                                </div>
                                </div>
                                <div flex="10" class="flex-10">
                                        <img ng-src="http://10.255.109.100/TESTService/Services/../Repository/ScheduleStatus/Locked.png" ng-altsrc="../../Images/Common/NoImage.png" onerror="this.src = $(this).attr('altSrc')" src="http://10.255.109.100/TESTService/Services/../Repository/ScheduleStatus/Locked.png">
                                </div>
                                </div>

                         </div><div class="widget-loading ng-hide layout-fill layout-align-center-center layout-row" ng-show="vm.loading" layout="" layout-fill="" layout-align="center center" aria-hidden="true"><div class="widget-loading-inner ng-hide" ng-show="vm.loading" aria-hidden="true"><md-progress-circular md-mode="indeterminate" aria-valuemin="0" aria-valuemax="100" role="progressbar" class="ng-isolate-scope" style="width: 50px; height: 50px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" style="width: 50px; height: 50px;"><path fill="none" transform="rotate(49.63717240968655 25, 25)" d="M23.589212129501437,47.455727055351694A22.5,22.5 0 0,0 28.277287287607944,47.2600401624634" style="stroke-width: 5px;"></path></svg></md-progress-circular></div></div></div><!-- end ngIf: scheduleBasicDetail.Client_ID!=0 -->
                        <!-- ngIf: scheduleBasicDetail.Client_ID==0 -->                                 
                        </div>
                        <div class="col-xs-2 dropdown-parent-div">
                            <div class="dropdown">
                            <i class="dropbtn fa fa-bars" aria-hidden="true"></i>
                                <div class="dropdown-content" style="margin-top:22px">
                                    <strong><a href="#" data-toggle="tooltip" data-placement="right" title="Export as XLS Of MetaData" ng-click="download(scheduleBasicDetail.Schedule_ID)"> <i class="fa fa-file-excel-o icon-4x dropdown-excel-button" aria-hidden="true">  </i></a></strong>
                                </div>
                                <div class="dropdown-content" style="margin-top:22px">
                                    <strong><a href="#" data-toggle="tooltip" data-placement="right" title="Export as XLS Of Translation" ng-click="download_Translation(scheduleBasicDetail.Schedule_ID)"> <i class="fa fa-file-excel-o icon-4x dropdown-excel-button" aria-hidden="true">  </i></a></strong>
                                </div>                                
                             </div>                                                  
                         </div>
                     </div><!-- end ngRepeat: scheduleBasicDetail in TEST_item.scheduleBasicDetailList --><div ng-repeat="scheduleBasicDetail in TEST_item.scheduleBasicDetailList" class="ng-scope">
                        <div class="col-xs-offset-2 col-xs-8" style="height:86px;">
                        <!-- ngIf: scheduleBasicDetail.Client_ID!=0 --><div class="tri_widget widget md-whiteframe-z2 ng-scope ng-isolate-scope flex layout-column" ng-class="::{'widget-overlay-title': vm.overlayTitle}" flex="" layout="column" ng-if="scheduleBasicDetail.Client_ID!=0" title-position="top" ng-click="redirect(scheduleBasicDetail.Schedule_ID,scheduleBasicDetail.Client_ID)" title="" role="button" tabindex="0"><!-- ngIf: ::(vm.title || vm.subtitle) --><div class="widget-content layout-column layout-align-start-stretch flex-order-2" layout="column" layout-align="" ng-class="{'layout-padding': vm.contentPadding}" ng-transclude="" flex-order="2">
                            <div layout="row" layout-wrap="" class="layout-wrap ng-scope layout-row">
                                <div flex="10" class="flex-10">
                                    <img class="AirlineScheduleListFirstTableTdImage" ng-src="http://10.255.109.100/TESTService/Services/../Repository/Airline/TEST/Logo.png" src="http://10.255.109.100/TESTService/Services/../Repository/Airline/TEST/Logo.png">
                                </div>
                                <div flex="80" class="Small_Padding_Left flex-80">
                                <div layout="row" class="layout-row">
                                  
                                     <div flex="33" id="title" class="ng-binding flex-33">HX-DEC16-01</div>
                                    <div flex="33" class="AirLineScheduleSystemName ng-binding flex-33">PAC eFX / PAC eX2 / Thales i5000</div>
                                    <div flex="33" class="flex-33"></div>
                                </div>
                                    <div layout="row" class="layout-row">
                                    <div flex="33" class="flex-33"><span class="TESTScheduleMonth ng-binding">December</span> <br>
                                    <span class="AirLineScheduleYear ng-binding">2016</span>   
                                    </div>
                                    <div flex="66" class="flex-66"><span class="AirLineScheduleAssets ng-binding">29 Assets</span><br>
                                          <span class="TESTScheduleAssets ng-binding">MOVIES / I-MOVIES / TV / OTHERS</span>   
                                    </div>
                                   
                                </div>
                                </div>
                                <div flex="10" class="flex-10">
                                        <img ng-src="http://10.255.109.100/DASHService/Services/../Repository/ScheduleStatus/Locked.png" ng-altsrc="../../Images/Common/NoImage.png" onerror="this.src = $(this).attr('altSrc')" src="http://10.255.109.100/DASHService/Services/../Repository/ScheduleStatus/Locked.png">
                                </div>
                                </div>

                         </div><div class="widget-loading ng-hide layout-fill layout-align-center-center layout-row" ng-show="vm.loading" layout="" layout-fill="" layout-align="center center" aria-hidden="true"><div class="widget-loading-inner ng-hide" ng-show="vm.loading" aria-hidden="true"><md-progress-circular md-mode="indeterminate" aria-valuemin="0" aria-valuemax="100" role="progressbar" class="ng-isolate-scope" style="width: 50px; height: 50px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" style="width: 50px; height: 50px;"><path fill="none" transform="rotate(49.63717240968655 25, 25)" d="M23.589212129501437,47.455727055351694A22.5,22.5 0 0,0 28.276617692292554,47.26013873493504" style="stroke-width: 5px;"></path></svg></md-progress-circular></div></div></div><!-- end ngIf: scheduleBasicDetail.Client_ID!=0 -->
                        <!-- ngIf: scheduleBasicDetail.Client_ID==0 -->                                 
                        </div>
                        <div class="col-xs-2 dropdown-parent-div">
                            <div class="dropdown">
                            <i class="dropbtn fa fa-bars" aria-hidden="true"></i>
                                <div class="dropdown-content" style="margin-top:22px">
                                    <strong><a href="#" data-toggle="tooltip" data-placement="right" title="Export as XLS Of MetaData" ng-click="download(scheduleBasicDetail.Schedule_ID)"> <i class="fa fa-file-excel-o icon-4x dropdown-excel-button" aria-hidden="true">  </i></a></strong>
                                </div>
                                <div class="dropdown-content" style="margin-top:22px">
                                    <strong><a href="#" data-toggle="tooltip" data-placement="right" title="Export as XLS Of Translation" ng-click="download_Translation(scheduleBasicDetail.Schedule_ID)"> <i class="fa fa-file-excel-o icon-4x dropdown-excel-button" aria-hidden="true">  </i></a></strong>
                                </div>                                
                             </div>                                                  
                         </div>
                     </div><!-- end ngRepeat: scheduleBasicDetail in Airline_item.scheduleBasicDetailList --><div ng-repeat="scheduleBasicDetail in Airline_item.scheduleBasicDetailList" class="ng-scope">
                        <div class="col-xs-offset-2 col-xs-8" style="height:86px;">
                        <!-- ngIf: scheduleBasicDetail.Client_ID!=0 --><div class="tri_widget widget md-whiteframe-z2 ng-scope ng-isolate-scope flex layout-column" ng-class="::{'widget-overlay-title': vm.overlayTitle}" flex="" layout="column" ng-if="scheduleBasicDetail.Client_ID!=0" title-position="top" ng-click="redirect(scheduleBasicDetail.Schedule_ID,scheduleBasicDetail.Client_ID)" title="" role="button" tabindex="0"><!-- ngIf: ::(vm.title || vm.subtitle) --><div class="widget-content layout-column layout-align-start-stretch flex-order-2" layout="column" layout-align="" ng-class="{'layout-padding': vm.contentPadding}" ng-transclude="" flex-order="2">
                            <div layout="row" layout-wrap="" class="layout-wrap ng-scope layout-row">
                                <div flex="10" class="flex-10">
                                    <img class="AirlineScheduleListFirstTableTdImage" ng-src="http://10.255.109.100/DASHService/Services/../Repository/Airline/Hong_Kong_Airlines/Logo.png" src="http://10.255.109.100/DASHService/Services/../Repository/Airline/Hong_Kong_Airlines/Logo.png">
                                </div>
                                <div flex="80" class="Small_Padding_Left flex-80">
                                <div layout="row" class="layout-row">
                                  
                                     <div flex="33" id="title" class="ng-binding flex-33">HX-SEP16-01</div>
                                    <div flex="33" class="AirLineScheduleSystemName ng-binding flex-33">PAC eFX / PAC eX2 / Thales i5000</div>
                                    <div flex="33" class="flex-33"></div>
                                </div>
                                    <div layout="row" class="layout-row">
                                    <div flex="33" class="flex-33"><span class="AirLineScheduleMonth ng-binding">September</span> <br>
                                    <span class="AirLineScheduleYear ng-binding">2016</span>   
                                    </div>
                                    <div flex="66" class="flex-66"><span class="AirLineScheduleAssets ng-binding">50 Assets</span><br>
                                          <span class="AirLineScheduleAssets ng-binding">MOVIES / I-MOVIES / TV / OTHERS</span>   
                                    </div>
                                   
                                </div>
                                </div>
                                <div flex="10" class="flex-10">
                                        <img ng-src="http://10.255.109.100/DASHService/Services/../Repository/ScheduleStatus/Locked.png" ng-altsrc="../../Images/Common/NoImage.png" onerror="this.src = $(this).attr('altSrc')" src="http://10.255.109.100/DASHService/Services/../Repository/ScheduleStatus/Locked.png">
                                </div>
                                </div>

                         </div><div class="widget-loading ng-hide layout-fill layout-align-center-center layout-row" ng-show="vm.loading" layout="" layout-fill="" layout-align="center center" aria-hidden="true"><div class="widget-loading-inner ng-hide" ng-show="vm.loading" aria-hidden="true"><md-progress-circular md-mode="indeterminate" aria-valuemin="0" aria-valuemax="100" role="progressbar" class="ng-isolate-scope" style="width: 50px; height: 50px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" style="width: 50px; height: 50px;"><path fill="none" transform="rotate(49.63717240968655 25, 25)" d="M23.589212129501437,47.455727055351694A22.5,22.5 0 0,0 28.275447404006268,47.260310966012774" style="stroke-width: 5px;"></path></svg></md-progress-circular></div></div></div><!-- end ngIf: scheduleBasicDetail.Client_ID!=0 -->
                        <!-- ngIf: scheduleBasicDetail.Client_ID==0 -->                                 
                        </div>
                        <div class="col-xs-2 dropdown-parent-div">
                            <div class="dropdown">
                            <i class="dropbtn fa fa-bars" aria-hidden="true"></i>
                                <div class="dropdown-content" style="margin-top:22px">
                                    <strong><a href="#" data-toggle="tooltip" data-placement="right" title="Export as XLS Of MetaData" ng-click="download(scheduleBasicDetail.Schedule_ID)"> <i class="fa fa-file-excel-o icon-4x dropdown-excel-button" aria-hidden="true">  </i></a></strong>
                                </div>
                                <div class="dropdown-content" style="margin-top:22px">
                                    <strong><a href="#" data-toggle="tooltip" data-placement="right" title="Export as XLS Of Translation" ng-click="download_Translation(scheduleBasicDetail.Schedule_ID)"> <i class="fa fa-file-excel-o icon-4x dropdown-excel-button" aria-hidden="true">  </i></a></strong>
                                </div>                                
                             </div>                                                  
                         </div>
                     </div><!-- end ngRepeat: scheduleBasicDetail in Airline_item.scheduleBasicDetailList --> 
                           
                    
                    <div class="col-xs-8 col-xs-offset-2  div_add_btn">  
                        <!-- ngIf: showAirlineCreateButton --><div class="col-xs-6 col-xs-offset-6 text-center add_btn_schedule ng-scope" ng-click="Show_AirName(Airline_item.Client_ID,Airline_item.ClientName,Airline_item.scheduleBasicDetailList[0].Schedule_ID)" data-toggle="modal" data-target="#myModal" data-ng-if="showAirlineCreateButton" role="button" tabindex="0">
                            <span class="fa fa-plus" aria-label="Create a Schedule">
                                
 </span>
 /div><!-- end ngIf: showAirlineCreateButton -->
 </div>
 </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

无论元素位于何处,您都可以使用此XPath

//div[@data-ng-if="showAirlineCreateButton"]