I would like to search for a link on a page by its domain name - possibly using contains()? And then only show the anchor text of that link.
I've been able to get all of the a tag using
//a[contains(text(), 'domain_name')]
but unable to retrieve just the anchor text. Can anybody help?
Just use the text() node:
//a[contains(#href, 'domain_name')]/text()
Related
I am very new to Xpath and html. Could anyone please tell me how to use xpath to extract the text ('Nicht verfugbar') shown in the attached pic?
Thanks a lot!
The web page I am talking about here is
https://de.louisvuitton.com/deu-de/produkte/nano-speedy-monogram-010575
You can try with
//span[#class='lv-stock-indicator lv-product-stock-indicator lv-product__stock list-label-m -not-available']/text()
The class of the span is unique, so it can be used for location.
More info:
https://www.guru99.com/xpath-selenium.html
I want to click on this element:
<a id="welcome" class="panelTrigger" href="#">Welcome Admin</a>
but I am not able to locate this element.
I have tried:
id=welcome, xpath=//*[#id="welcome"]
Click Element or Click Link but it is not working. Can you please help me?
I think you should be fine any of the lines below:
Click Link id:welcome
Click Link Welcome Admin
Based on the documentation:
When using the default locator strategy, links are searched using
id, name, href and the link text.
So if the ID does not happens to be unique you can still refer to the link by its text.
Try this way
Scroll To Element xpath ${element_locator}
Wait Until Element Is Visible ${element_locator} timeout=30s
Click Element ${element_locator}
I'm trying to use Watir to grab a specific link on a page:
Screenshot: Here is the href I am trying to grab.
My guess is I need to specify the ancestor element biz-website(?) then traverse down to the a tag and grab its href somehow, but I'm not sure what the syntax of my code would need to be do that.
Any ideas or tips?
You should be able to get the value of the href with
browser.span(:class, 'biz-website').a.href
If the class 'biz-website' is not unique for spans on your page, you can also use 'biz-website js-add-url-tagging'. If that is still not unique, you could also try
browser.span(:text, 'Business website').parent.a.href
I'm using Chrome Data Miner, and so far, failing to extract the data from my query: http://www.allinlondon.co.uk/restaurants.php?type=name&rest=gluten+free
How to code the Next Element Xpath for this website? I tried all the possible web sources, nothing worked.
Thanks in advance!
You could look for a tags (//a) whose descendant::text() starts with "Next" and then get the href attribute of that a element.
% xpquery -p HTML '//a[starts-with(descendant::text(), "Next")]/#href' 'http://www.allinlondon.co.uk/restaurants.php?type=name&rest=gluten+free'
href="http://www.allinlondon.co.uk/restaurants.php?type=name&tube=0&rest=glutenfree®ion=0&cuisine=0&start=30&ordering=&expand="
I'm making an Xpath as part of a scraping project I'm working on. However, the only defining feature of the text I want is the title attribute of the enclosing <a> tag like so:
This is what I want to scrape
Is it at all possible to refer to that title and create a path like this?
//tr/td[style='vertical-align:top']/a[title='Vacancy details']
Attributes in XPath expressions need to be prefixed with the # symbol...
//tr/td/a[#title='Vacancy details']
//tr/td/a[#title='Vacancy details']/#title
You can grab just the title if that's all you want