gpt4 book ai didi

javascript - 如何使用 selenium web 驱动程序单击导航栏

转载 作者:行者123 更新时间:2023-11-28 19:03:42 25 4
gpt4 key购买 nike

我想使用 Selenium Web 驱动程序单击导航栏

我的 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&amp;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();

对此有任何帮助 - 会有帮助

最佳答案

如果没有xpath,请使用链接文本点击

driverIE.findElement(By.linkText("Login")).click()

如果您不确定确切的链接文本,也可以使用部分匹配来执行相同的操作

driver.findElement(By.partialLinkText("Log")).click();

关于javascript - 如何使用 selenium web 驱动程序单击导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32087722/

25 4 0