如果Frame不可用,如何在selenium web驱动程序中切换到div

时间:2018-03-06 21:45:21

标签: java selenium

<div class="panel panel-default ng-scope" ng-repeat="leftNavParent in
 leftNavCtrl.displayedNavItems">
    <div class="panel-heading">
       <h4 class="panel-title">
            <a ng-if="leftNavParent.ChildNavigationLinks.length > 0" 
              href="#!" class="activeContent ng-binding ng-scope" ng-
              click="leftNavCtrl.leftNavHeaderClicked(leftNavParent)">
                Modules
            </a>
        </h4>
    </div>
     <div class="panel-collapse collapse in slide" ng-
      show="leftNavParent.Expand" style="display: block;">
       <div class="panel-body">
            <ul class="list-group">
                <li ng-repeat="childNavParent in 
                 leftNavParent.ChildNavigationLinks" class="list-group-item 
                 ng-scope" ng-class="{'active' : 
                 leftNavCtrl.selectedNavItemId == childNavParent.Id}">
                    <a class="inboxsublink ng-binding" ui-sref-opts="
                      {reload: true}" ui-sref="AAA({ action: 'AAADashBoard', 
                       role: '18'})" href="18">Interactions
                       <span ng-if="childNavParent.HasCount" class="badge 
                         red-background pull-right ng-scope">
                            <span ng-if="childNavParent.Count >= 0" 
                             class="ng-binding ng-scope" style="">0</span>
                         </span>
                     </a>
                    <ul class="list-group sub_list slide ng-scope ng-hide" 
                    ng-if="childNavParent.ChildNavigationLinks.length > 0" 
                    ng-show="childNavParent.Expand" style="display: none;">
                        <li class="list-group-item list-group-item-sub ng-
                            scope" ng-repeat="childNavParentChild in 
                            childNavParent.ChildNavigationLinks" ng-class="
                            {'active' : leftNavCtrl.selectedNavItemId == 
                            childNavParentChild.Id}" style="">
                            <a class="inboxsublink ng-binding" ui-sref-
                            opts="{reload: true}" ui-sref="AAA({ action: 
                            'DashBoard', role: '19' })" href="19">
                                Administrator
                            </a>           
                        </li>
                    </ul>
                </div>
            </ul>
        </div>
    </div>
</div>

//我在这里改变了我的代码。我想要选择模块的元素,当我点击模块时,会打开子菜单。这实际上是右侧的菜单。我认为它是动态生成的

1 个答案:

答案 0 :(得分:0)

根据 HTML ,您已经分享了如何找到元素的要求 class =“活动链接cmm_action_link btn btn-primary”与两个节点/ webelements完全匹配,如下所示:

  • 首先:

    <a class="Activity-link cmm_action_link btn btn-primary" ui-sref="CMMRecordManagement({action: 'CreateRecord', pDashboardName: 'IHCP'})" href="/CMM">Create New Record</a>
    
  • 第二:

    driver.findElement(By.linkText("Search Records")).click();
    //or
    driver.findElement(By.xpath("//a[@class='Activity-link cmm_action_link btn btn-primary' and @href='/SearchMM-Search-']")).click();
    

但是,要点击上面提到的链接,您可以使用以下代码行:

  • 搜索记录

    driver.findElement(By.linkText("Create New Record")).click();
    //or
    driver.findElement(By.xpath("//a[@class='Activity-link cmm_action_link btn btn-primary' and @href='/CMM']")).click();
    
  • 创建新记录

    <input type="text" data-inputmask='"mask": "+\\92999-9999999"' data-mask />