How to write xpath for this code - selenium

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"))

Related

XPath not working for one of the selenium scenario

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')]

Selenium and Xpath - accessing elements adjacent to each other

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

Click on button without id

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(), 'Мои круги')]

Webdriver: How to select anchor link under DIV?

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"));

Multiple buttons on right hand side of Header

I would like to have more than one button on the right side of the Header bar. The docs say you can customize using a DIV, but when I do that the buttons do not have their normal style. Any advice?
The above example puts more than buttons on the header but they are all positioned to the left of the header. I think you can group your buttons in a controlgroup and position the control the group to the right of the header. Maybe something like this:
<div data-type="horizontal" data-role="controlgroup" class="ui-btn-right">
//have your button here
</div>
Hope this helps.
This is how I did it, seems clean.
HTML
<div id="myHeader" data-role="header" data-theme="a">
<span class="ui-title"></span>
<div class="ui-btn-right">
<a id="myButton1" class="headerButton" href="#" data-role="button"></a>
<a id="myButton2" class="headerButton" href="#" data-role="button"></a>
</div>
</div>
CSS
.headerButton {
float: left;
margin-right: 5px!important;
}
I've seen this done in the footer (Shown Here), might give you an idea for the header or toolbar
You can use the grid class.
<div class="ui-grid-a ui-btn-right">
<div class="ui-block-a" ><a href="#" data-role="button" data-inline="true" >Button1</a></div>
<div class="ui-block-b" ><a href="#" data-role="button" data-inline="true" >Button2</a></div>
</div>
<a href="#" class="ui-btn-right ui-btn ui-btn-up-a ui-btn-icon-left
ui-btn-corner-all ui-shadow" data-rel="back" data-icon="cancel"
data-theme="a">
<span class="ui-btn-inner ui-btn-corner-all">
<span class="ui-btn-text">Cancel</span>
<span class="ui-icon ui-icon-arrow-l ui-icon-shadow"></span>
</span>
</a>