我想点击一个包含img标签的按钮
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Home.png" height="60px" width="60px" title="My Home">
</button>
它的绝对xpath是
/html/body/div[2]/div/div/div[2]/div[1]/div[2]/div/tooltip/tip-cont/tooltip/a/button
当我使用这个相对xpath单击它时,它会单击该元素,但是当我使用相对xpath时,
(//button[@class='home-page-img-btn'])[9]
它说它点击了但在我的浏览器上没有点击任何内容。我可以写什么不使用绝对xpath?
这是整个html代码,供检查元素
参考<html lang="en" ng-app="caleajoMemberApp" class="ng-scope"><head>....</head>
<body>
<div id="loader" ng-show="showLoader" class="ng-hide"></div>
<!--<div class="nav-adjustment"></div>-->
<!-- ngInclude: '../common/html/nav-bar.html' --><nav class="caleajo-nav-top ng-scope" ng-include="'../common/html/nav-bar.html'"><div class="container top-nav-panel ng-scope" ng-controller="HeaderController as ctrl" style="color: whitesmoke">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header col-md-4 col-sm-4 zero-padding">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-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>
<a class="navbar-brand" href="#/home">
<img height="40" style="height: 40px;" src="../common/img/New-Caleajo-Logo-04.png" class="caleajo-brand">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<!--<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>-->
<div class="pull-right col-lg-8 col-md-8 col-sm-8 col-xs-12">
<div class="row" style="height: 50px">
<!-- <div class="pull-right col-md-8 col-sm-12 col-xs-12">
<div class="input-group" style="padding: 20px">
<!– <input type="text" class="form-control"
placeholder="{{ 'cmnStr.Search' | translate}}"> <span
class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>–>
</div>
</div>-->
</div>
<!--input-group -->
<div class="row login-menu-row" style="color: #000000; font-weight: bold;margin-bottom: 25px;margin-top: -15px">
<li style="height: 40px">
<!-- ngIf: showNotificationIcon --><ul ng-if="showNotificationIcon" class="ng-scope">
<a ng-click="ctrl.gotoUpdate()">
<!--<img src="../common/img/My-Messages.png" style="height: 40px;width: 40px">-->
<i class="fa fa-bell-o fa-lg" aria-hidden="true" style="font-size: 30px;cursor: pointer;padding: 0px;"></i>
<!-- ngIf: notificationCounts.ALL != 0 --><span class="badge badge-notify-nav ng-binding ng-scope" ng-if="notificationCounts.ALL != 0">3</span><!-- end ngIf: notificationCounts.ALL != 0 -->
</a>
</ul><!-- end ngIf: showNotificationIcon -->
<ul style="border-left: #000000 solid medium;"><a href="/logout"><span class="ng-binding">Log Out</span></a></ul>
<ul style="border-left: #000000 solid medium;"><a href="#help"><span class="ng-binding">Help</span></a></ul>
</li>
</div>
</div>
</div>
</div>
<!-- /.navbar-collapse -->
<!-- /.container-fluid -->
</nav>
<div class="wrapper" style="margin-top: 0px">
<div xmlns="http://www.w3.org/1999/html">
<div class="container-fluid" style="padding: 0px">
<div class="row visible-xs hidden-sm hidden-md top-menu-panel">
<div class="row">
<div class="col-xs-offset-1 col-xs-1">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Home' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Home"> <a ui-sref="home" href="#/home">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Home.png" class="home-page-img" title="My Home">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Home</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
<div class="col-xs-offset-1 col-xs-1 ">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Profile' | translate}}" tooltip-side="bottom" class="tooltips _bottom _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Profile"> <a ui-sref="profileDashboard" href="#/profile-dashboard">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Profile.png" class="home-page-img" title="My Profile">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Profile</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
<div class="col-xs-offset-1 col-xs-1">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Jobs' | translate}}" tooltip-side="bottom" class="tooltips _bottom _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Jobs"> <a ui-sref="memberJobListing" href="#/job">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Jobs.png" class="home-page-img" title="My Jobs">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Jobs</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
<div class="col-xs-offset-1 col-xs-1 ">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Applications' | translate}}" tooltip-side="left" class="tooltips _left _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Applications"> <a ui-sref="memberJobApplication" href="#/application">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Applications.png" class="home-page-img" title="My Applications">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Applications</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-xs-offset-1 col-xs-1">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Interviews' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Interviews"> <a ui-sref="myInterview" href="#/my_interview">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Interviews.png" class="home-page-img" title="My Interviews">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Interviews</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
<div class="col-xs-offset-1 col-xs-1">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'CV' | translate}}" tooltip-side="bottom" class="tooltips _bottom _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My CV"> <a ui-sref="cvList" href="#/cv">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/CV.png" class="home-page-img" title="My CV">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My CV</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
<!-- ngIf: ShowJourney --><div class="col-xs-offset-1 col-xs-1 ng-scope" ng-if="ShowJourney">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Journey' | translate}}" tooltip-side="bottom" class="tooltips _bottom _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Journey"> <a ui-sref="myJourneyWizard.talent" href="#/my_journey/talent">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Journey.png" class="home-page-img" title="My Journey">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Journey</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div><!-- end ngIf: ShowJourney -->
<div class="col-xs-offset-1 col-xs-1">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Files' | translate}}" tooltip-side="bottom" class="tooltips _bottom _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Files"> <a ui-sref="uploads" href="#/uploads">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Files.png" class="home-page-img" title="My Files">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Files</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
</div>
<div class="row-fluid row-equal" style="margin: 0px; padding: 0px">
<div class="col-lg-1 col-md-1 hidden-xs hidden-sm left-nav-panel col-equal text-center" align="center" style="z-index: 9999999">
<div class="row">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Home' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Home"> <a class="hvr-grow" ui-sref="home" href="#/home">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Home.png" height="60px" width="60px" title="My Home">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Home</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 " style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Profile' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Profile"> <a class="hvr-grow" ui-sref="profileDashboard" href="#/profile-dashboard">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Profile.png" height="60px" width="60px" title="My Profile">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Profile</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Jobs' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Jobs"> <a class="hvr-grow" ui-sref="memberJobListing" href="#/job">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Jobs.png" height="60px" width="60px" title="My Jobs">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Jobs</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Applications' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Applications"> <a class="hvr-grow" ui-sref="memberJobApplication" href="#/application">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Applications.png" height="60px" width="60px" title="My Applications">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Applications</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Interviews' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Interviews"> <a class="hvr-grow" ui-sref="myInterview" href="#/my_interview">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Interviews.png" height="60px" width="60px" title="My Interviews">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Interviews</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'CV' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My CV"> <a class="hvr-grow" ui-sref="cvList" href="#/cv">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/CV.png" height="60px" width="60px" title="My CV">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My CV</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<!-- ngIf: ShowJourney --><div class="row ng-scope" ng-if="ShowJourney">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Journey' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Journey"> <a class="hvr-grow" ui-sref="myJourneyWizard.talent" href="#/my_journey/talent">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Journey.png" height="60px" width="60px" title="My Journey">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Journey</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div><!-- end ngIf: ShowJourney -->
<div class="row">
<div class="col-lg-12 col-md-12" style="padding-left: 0px;">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Files' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Files"> <a class="hvr-grow" ui-sref="uploads" href="#/uploads">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Files.png" height="60px" width="60px" title="My Files">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Files</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
</div>
<div class="row hidden-xs visible-sm hidden-md top-menu-panel">
<div class="row">
<div class="col-sm-12">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Home' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Home"> <a ui-sref="home" href="#/home">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Home.png" class="home-page-img" title="My Home">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Home</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Profile' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Profile"> <a ui-sref="profileDashboard" href="#/profile-dashboard">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Profile.png" class="home-page-img" title="My Profile">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Profile</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Jobs' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Jobs"> <a ui-sref="memberJobListing" href="#/job">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Jobs.png" class="home-page-img" title="My Jobs">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Jobs</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-sm-12 ">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Applications' | translate}}" tooltip-side="left" class="tooltips _left _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Applications"> <a ui-sref="memberJobApplication" href="#/application">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Applications.png" class="home-page-img" title="My Applications">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Applications</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-sm-12 ">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Interviews' | translate}}" tooltip-side="left" class="tooltips _left _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Interviews"> <a ui-sref="myInterview" href="#/my_interview">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Interviews.png" class="home-page-img" title="My Interviews">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Interviews</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<div class="row">
<div class="col-sm-12 ">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'CV' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My CV"> <a ui-sref="cvList" href="#/cv">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/CV.png" class="home-page-img" title="My CV">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My CV</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
<!-- ngIf: ShowJourney --><div class="row ng-scope" ng-if="ShowJourney">
<div class="col-sm-12">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Journey' | translate}}" tooltip-side="right" class="tooltips _right _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Journey"> <a ui-sref="myJourneyWizard.talent" href="#/my_journey/talent">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Journey.png" class="home-page-img" title="My Journey">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Journey</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div><!-- end ngIf: ShowJourney -->
<div class="row">
<div class="col-sm-12">
<!-- tooltips: --><tooltip tooltip-template="{{'My' | translate}} {{'Files' | translate}}" tooltip-side="bottom" class="tooltips _bottom _steady _ready"><tip-cont><tooltip class="ng-scope" tooltip-template="My Files"> <a ui-sref="uploads" href="#/uploads">
<button type="button" class="home-page-img-btn">
<img src="img/home-white-icon-only/Files.png" class="home-page-img" title="My Files">
</button>
</a> </tooltip></tip-cont><tip class=""><tip-tip><span id="close-button" style="display: none;">×</span>My Files</tip-tip><tip-arrow></tip-arrow></tip></tooltip>
</div>
</div>
</div>
<div class="col-md-11 col-lg-11 col-sm-12 col-equal ui-view-panel" id="body" style="margin: 0px; min-height: 815px;">
<!-- ngIf: (breadcrumb && breadcrumb.length > 0) --><!-- ngInclude: '../common/html/breadcrumb.html' --><div class="row-fluid ng-scope" ng-if="(breadcrumb && breadcrumb.length > 0)" ng-include="'../common/html/breadcrumb.html'"><!-- ngIf: breadcrumb --><h4 ng-if="breadcrumb" style="font-size: 16px;padding-left: 10px;padding-bottom: 0px;" class="ng-scope">
<!-- ngRepeat: link in breadcrumb --><span ng-repeat="link in breadcrumb" class="breadcrumb-link ng-scope">
<!-- ngIf: link.name --><a href="#/home" class="breadcrumb-link ng-binding ng-scope" ng-if="link.name "> Home</a><!-- end ngIf: link.name --> <!-- ngIf: link.name --><i class="fa fa-circle ng-scope" style="font-size: 8px;vertical-align: middle" aria-hidden="true" ng-if="link.name "></i><!-- end ngIf: link.name -->
</span><!-- end ngRepeat: link in breadcrumb -->
</h4><!-- end ngIf: breadcrumb -->
<!-- ngIf: pageHeader && !hideTitle --></div><!-- end ngIf: (breadcrumb && breadcrumb.length > 0) -->
</div>
</div>
</div>
</div>
</div>
<div class="ng-toast ng-toast--center ng-toast--top ng-toast--animate-slide"><ul class="ng-toast__list"><!-- ngRepeat: message in messages --></ul></div>
PS。我删除了内容和脚本,因为文本已超过字符限制
答案 0 :(得分:0)
我认为你可能会认真简化你的表达:
//button[@class = 'home-page-img-btn']
或者,另外检查img
元素的标题(看起来这样可以保证唯一性):
//button[@class = 'home-page-img-btn' and img/@title = 'My Home']
答案 1 :(得分:0)
尝试使用此亲戚XPath
:
//button[@class="home-page-img-btn"][img[@src="img/home-white-icon-only/Home.png"]]
答案 2 :(得分:0)
使用绝对XPath不是好习惯,因为从起始节点查找元素需要更多时间使用相对路径来定位元素的更好方法。
还有一种更好的方法来制作你的自定义xpath,然后复制&amp;从Firepath
//button/img[@title='My Home']
或
//button/img[@src='img/home-white-icon-only/Home.png']
答案 3 :(得分:0)
创建Xpath时,您必须非常确定以下几点
对于您的解决方案,请尝试以下Xpath:
//button//img[@title='My Home']