Locating image in selenium - xpath

I want to check if a logo (image) is displayed or not but i am unable to find out the xpath for the same.The html code is as below:
<div class="page-wrapper">
<a class="brand pull-left" href="www.com">The Logo<\a>
What could be the possible xpath for verifying "The Logo " is displayed.

May one of these works:
//a[contains(text(), 'The Logo')]
//a[contains(text(), 'The Logo') and #href='www.com']
//div[#class='page-wrapper']/a[contains(text(), 'The Logo')]
//div[#class='page-wrapper']/a[contains(text(), 'The Logo') and #href='www.com']

Related

How to have xpath of with <i> tag

I have a html code like this
<div>
<a href="http://test" target="_blank">
<i>this is test </i>
"site for computer"
</a>
</div>
so how can I capture this link "This is a test site for computer" by xpath?
If you want to find text of a then use:
//div/a
And if you want web address of #href then use:
//div/a/#href

Xpath for any html element containing specific text inside html tag

Need to find xpath that matches any html tag that contains the word sidebar in any html tag. Example:
<p class='my class'>This is some text</p>
<h1 class='btn sidebar btn-now'><p>We have more text here</p><p> and anoter text here</p></div>
<div id='something here'>New text here</div>
<div id='something sidebar here'>New text again</div>
<nav class='this sidebar btn'>This is my nav</nav>
<sidebar><div>This is some text</div></sidebar>
I need xpath to get any html element that has word 'sidebar' between starting < and ending > html tag, be it class, id or html tag name. In the above example I need to get as result:
<h1 class='btn sidebar btn-now'><p>We have more text here</p><p> and anoter text here</p></div>
<div id='something sidebar here'>New text again</div>
<nav class='this sidebar btn'>This is my nav</nav>
<sidebar><div>This is some text</div></sidebar>
Needs to be xpath not regex
Try below and let me know if it's not what you're searching for:
//*[contains(#*, "sidebar") or contains(name(), "sidebar")]
contains(#*, "sidebar") means node with any attribute that contains "sidebar"
contains(name(), "sidebar") - node name that contains "sidebar"
If you need only id or class to contain "sidebar":
//*[contains(#id, "sidebar") or contains(#class, "sidebar") or contains(name(), "sidebar")]

Scraping text within several span tags (Ruby & Nokogiri)

I am trying to scrape "Description" from this HTML structure
<div class="menu-index-page__item-content">
<h6 class="menu-index-page__item-title">
<span> Item title </span>
</h6>
<p class="menu-index-page__item-desc">
<span>
<span>
<span>Description</span>
</span>
</span>
Each tag has an element with it that I don't know how to handle:
data-reactid=".3wrqgx5340.3.5.0.4:$523105.2.$3959254.$menuItemContent.1.0"
Each data-reactid is different. So if I target this attribute I will scrape stuff I don't want.
I've tried .search .xpath, using tags and classes but nothing seems to work.
Is there a way to say: give me the p tag that has a class="menu-index-page__item-desc" and scrape the 3rd span from there?
You can get the required value via xpath
//text()[contains(.,'Description')]
You code and xpath:

Get specific text value of parent without child

I'm trying to use Xpath to get the text of the parent anchor without also getting the text from the span of the example below:
<a id="readingListBtn" class="btn btn-transparent" title="Reading List" href="javascript:void(0);">
<span class="icon icon_headerBookmark">Header Bookmark</span>
0
</a>
The Xpath I'm using (//a[#id = 'readingListBtn']) returns "Header Bookmark0", but I'm just interested in the "0" part.
Just get the direct text child:
//a[#id = 'readingListBtn']/text()

How to click on anchor <a> tag from Canoo webtest?

Our team replaced a submit button with the following anchor tag:
<a class="l-btn" onclick="onFormSubmit(this.form)" Style="width: 80px; text-align:center;">
<span class="l-btn-left">
<span class="l-btn-text">Save</span>
</span>
</a>
I retrieved xpath from XPather, and tried to use from canoo webtest to click on it, but received "failed: Link not found".
Does anyone know how to simulate click on the above?
Thanks.
<clickLink xpath="//a[#class='l-btn']" description="Click first a tag with class l-btn" />
See clickLink documentation
clickLink xpath="//a[contains(#onclick,'onFormSubmit')]
description="click link with onclick property that contain the word
onFormSubmit"
will look for the link with xpath property onclick that contain a value 'onFormSubmit'

Resources