HTML
<div data-testid="signin-back-button" class="white-arrow">
<a href="/" class="back-text" onclick="backBtnClick()">
<img class="back-arrow-white" src="/images/arrow-left-white.svg" aria-hidden="true">
Back
</a>
</div>
I have written xpath as
//a[#onclick='backBtnClick()']/img[contains(text(),'Back')]
There is not need to rely on text, please use below xpath
//a[#onclick='backBtnClick()']//child::img[contains(#src,'images/arrow-left-white.svg')]
use double slash in your xpath
//a[#onclick='backBtnClick()']//img[contains(text(),'Back')]
Related
In the example below I'm trying to click on Follow Me where the adjacent(ish) <div> is equal to David. This is one of many <div class='_1m' on the page all with the same structure.(does that make sense?)
Sorry first time posting a problem and a forgot one major detail. I know that I'm looking for David but I don't know what the 'Follow Me' Value will be. It changes on each record.
<div class="_1m">
<div class="_8h"><img src="/2323.GIF" /></div>
<div class="_1j">
<div class="_1c">David<span class="_13">abc</span></div>
<div>
<span class="_1v">ABCD</span>
<span class="_1v">1234</span>
</div>
<div>7890</div>
</div>
<div class="_3h">
<div class="_n0">
<span class="_bn"><span class="_la">Follow Me</span></span>
</div>
</div>
</div>
To click on Follow Me where the adjacent <div> contains the text David you can use the following Locator Strategy:
Using xpath and following:
//div[contains(., 'David')]//following::span[3]/span
Using xpath, following and the text Follow Me:
//div[contains(., 'David')]//following::span[3]/span[text()='Follow Me']
Use below xpath //div[#class='_1c'][contains(.,'David')]/../following-sibling::div//span[#class='_la'][contains(.,'Follow Me')]
Explaination:
//div[#class='_1c'][contains(.,'David')] loate the David
/.. move to one parent node of David because follow me emement is sibling of that parent div
/following-sibling::div locate immediate following sibling div
//span[#class='_la'][contains(.,'Follow Me')] Loate the span which has Follow me text
I'm trying to get the webdriver to click on the text "Breaking Things" through xpath/css selectors to no avail. Here is the HTML
<div class="org-option" ng-repeat="Org in Organizations" aria-label="Select Breaking Things Organization" ng-click="Org.SelectOrg()" role="button" tabindex="0">
<div class="data">
<div class="data-relative">
<!---->
<div class="image-wrapper" ng-show="Org.HasImage" ng-if="Org.HasImage" aria-hidden="false">
<img class="onboard-logo" ng-src="/apiimage/organizations/f1544944fac34442998a05890c400338-0" src="/apiimage/organizations/f1544944fac34442998a05890c400338-0">
</div>
<!---->
<div class="image-wrapper ng-hide" ng-show="!Org.HasImage" aria-hidden="true">
<div class="image-placeholder">
<div class="center-icon gicon-panorama"></div>
</div>
</div>
<div class="name-wrapper">
<div>Breaking Things</div>
Here is what I'm doing with the driver:
chromeDriver.findElement(By.xpath("//div[#class='name wrapper']//[text()='Breaking Things']")).click();
However it never clicks, what am I missing? I've also tried implicit waits etc with no results.
You should specify exact node name div or wild-card for "any node" - * in this part
//[text()='Breaking Things']
like below:
"//div[#class='name-wrapper']//div[text()='Breaking Things']"
or
"//div[#class='name-wrapper']//*[text()='Breaking Things']"
The class name is name-wrapper. The - is important
chromeDriver.findElement(By.xpath("//div[#class='name-wrapper']//[text()='Breaking Things']")).click();
In #class='name wrapper' you are actually telling the driver to look for an WebElement with two classes, name and wrapper.
This is my code
i am not able to find the xpath for this code plz help me
<div class="col-md-3">
<div class="box">
<div class="box-title">
<a href="/MCare_Test/Auhmc/Admin/Operator/List">
<h3>
<i class="fa fa-user"/>
Operators
</h3>
</a>
</div>
</div>
</div>
Please try below Xpath:-
//i[#class='fa fa-user' and contains(.,'Operators')]
Please get back to me if still facing any issue :)
Hope it will help you :)
This should do the trick
//i[#class="fa fa-user"]
Try the below xpath :
//h3[contains(text(),'Operators')]
If you're looking to use driver.findElement(By.xpath("whatever")) you could instead use driver.findElement(By.linkText("Operators"))
How click button in webdriver without any id, values. Class of button is changing dynamically.
Sample:
<div class="d-k-l d-y-r-c g-h-f-Ck b-Qb" role="button" style="-moz-user-select: none;" tabindex="0" aria-haspopup="true">
<div class="d-k-l d-y-r-c-ha">
Мои круги
</div>
<div class="d-k-l d-y-r-c-Qa"></div>
</div>
Thx.
Show more HTML please. So that we can find something useful in the context.
Currently the only possible way is to use XPath' text()
.//*[#role='button']/*[contains(text(), 'Мои круги')]
If you are sure relevant elements are div, you can use
.//div[#role='button']/div[contains(text(), 'Мои круги')]
In below code when I use //a[text()='My Process1' in Firebug it evaluates xpath and returns correctly, however when I try to use the same for finding an element using WebDriver I get NoSuchElement exception....any ideas what I might be doing wrong?
<div class="abbd" style="">
<ul class="New-type">
<li class="abcmenuitem" id="yui-gen10" groupindex="0" index="3">My Process1</li>
<li class="abcmenuitem" id="yui-gen11" groupindex="0" index="4">My Process2</li>
</ul>
</div>
webDriver.findElment(By.linkText("My Process1"));