我想使用selenium web driver点击导航栏
我的Html代码是
<div class="navbar-inner">
<div class="container">
<a class="navbar-brand " ui-sref="home" href="#/"><i class="glyphicon glyphicon-home"></i> iWatch Project</a>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse ng-scope" id="bs-navbar-collapse-1" data-ng-controller="uiUserNavigationController">
<ul class=" nav navbar-nav">
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="contractList" href="#/contract"><i class="glyphicon glyphicon-plus"></i> Contract Information</a></li>
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="civilList" href="#/civil"><i class="glyphicon glyphicon-plus"></i> Civil </a></li>
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="emList" href="#/em"><i class="glyphicon glyphicon-plus"></i> E&M </a></li>
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="safetyList" href="#/safety"><i class="glyphicon glyphicon-plus"></i> Safety </a></li>
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="workOrderList" href="#/workOrder"><i class="glyphicon glyphicon-plus"></i> Utility Diversion </a></li>
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="iPadView" href="#/iPadView"><i class="glyphicon glyphicon-plus"></i> iPad View</a></li>
<li class="dropdown ng-hide" data-ng-hide="!userInfo.isAuthenticated">
<a class="btn dropdown-toggle ng-binding" href="#" aria-haspopup="true" aria-expanded="false">
Hi, <i class="glyphicon glyphicon-user"></i> !
</a>
<ul class="dropdown-menu">
<li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a ui-sref="user.intray" href="#/user/intray"><i class="glyphicon glyphicon-tasks"></i> My Tasks</a></li>
<li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="requestAccess.CV" href="#/requestAccess/CV"><i class="glyphicon glyphicon-eye-open"></i> Request Access</a></li>
<li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a ui-sref="userChangePassword" href="#/changepassword"><i class="glyphicon glyphicon-lock"></i> Change Password</a></li>
<!--<li data-ng-hide="!userInfo.isAuthenticated"><a ui-sref="userSettings"><i class="glyphicon glyphicon-edit"></i> User Settings</a></li>-->
<li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a ui-sref="userClaims" href="#/userClaims"><i class="glyphicon glyphicon-wrench"></i> User Claims</a></li>
<li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a href="" data-ng-click="logOut()"><i class="glyphicon glyphicon-log-out"></i> Logout</a></li>
</ul>
</li>
<li data-ng-hide="userInfo.isAuthenticated" class=""><a href="" data-ng-click="LogIn()"><i class="glyphicon glyphicon-log-in"></i> Login</a></li>
</ul>
</div>
</div>
</div>
我想点击selenium中标记的部分。
**<a href="" data-ng-click="LogIn()">**
我尝试了什么
driverIE.findElement(By.cssSelector("a[href*=LogIn()]")).click();
对此有任何帮助 - 会有所帮助
答案 0 :(得分:2)
如果没有xpath
,请点击链接文字driverIE.findElement(By.linkText("Login")).click()
如果您不确定确切的链接文本
,也可以使用部分匹配来执行相同的操作driver.findElement(By.partialLinkText("Log")).click();
答案 1 :(得分:1)
您也可以使用 xpath :
来获取此元素 driverIE.findElement(By.xpath("//a[@data-ng-click='LogIn()']")).click();