Any idea how to get /includes/images/large/BW93942/hermes-swift-retourne-kelly-32-indigo-1.jpg from here with it xpath?
/<img class="cloudzoom-gallery img-responsive cloudzoom-gallery-active" src="/includes/images/thumb/BW93942/xhermes-swift-retourne-kelly-32-indigo-1.jpg.pagespeed.ic.PQKVquZdzC.webp" data-cloudzoom="useZoom: '.cloudzoom', image: '/includes/images/BW93942/hermes-swift-retourne-kelly-32-indigo-1.jpg', zoomImage: '*/includes/images/large/BW93942/hermes-swift-retourne-kelly-32-indigo-1.jpg*' " pagespeed_url_hash="271624911" onload="pagespeed.CriticalImages.checkImageForCriticality(this);">
try Below
//img/#src
OR
//img[#class='cloudzoom-gallery img-responsive cloudzoom-gallery-active']/#src
Hope it will help you :)
You could use the XPath string function substring-before to grab the part of the #src attribute which comes before .pagespeed. When applied the the HTML you posted, the XPath
substring-before(//img[#class="cloudzoom-gallery img-responsive cloudzoom-gallery-active"]/#src, ".pagespeed")
yields
/includes/images/thumb/BW93942/xhermes-swift-retourne-kelly-32-indigo-1.jpg
Related
<p><span class="label">key</span>value</p>
How am I able to get just the "value" out using xPath? I managed to get to the element using the following expression:
//span[#class='label']/..
Try this one to get required value:
//p[span[#class='label']]/text()
You just have to use text() to get the text from the p
//span[#class='label']/../text()
I would like to find "How are you?" using xpath with this part of html :
<li>Hello<span class="redS bold">How are you ?</span></li
I tried with :
//span[contains(#class, 'redS bold') and text() = 'Hello']
Thanks in advance for your help
maybe
//span[contains(text(),'How are you')]
? or maybe
//span[contains(#class,'redS bold') and contains(text(),'How are you')]
div class="ydpbfddd73dsignature" >......
How do I use xpath to get whatever text comes after this tag?
I tried doing this
nokogiri_html=Nokogiri::HTML html
nokogiri_html.xpath('//div[#class="/.*signature/"]')
But it doesn't work.
You can apply below XPath:
//div[substring(#class, string-length(#class) - 8)="signature"]
which means return div node which has "signature" as last 9 characters of class name
suppose I have this structure:
<div class="a" attribute="foo">
<div class="b">
<span>Text Example</span>
</div>
</div>
In xpath, I would like to retrieve the value of the attribute "attribute" given I have the text inside: Text Example
If I use this xpath:
.//*[#class='a']//*[text()='Text Example']
It returns the element span, but I need the div.a, because I need to get the value of the attribute through Selenium WebDriver
Hey there are lot of ways by which you can figure it out.
So lets say Text Example is given, you can identify it using this text:-
//span[text()='Text Example']/../.. --> If you know its 2 level up
OR
//span[text()='Text Example']/ancestor::div[#class='a'] --> If you don't know how many level up this `div` is
Above 2 xpaths can be used if you only want to identify the element using Text Example, if you don't want to iterate through this text. There are simple ways to identify it directly:-
//div[#class='a']
From your question itself you have mentioned the answer for it
but I need the div.a,
try this
driver.findElement(By.cssSelector("div.a")).getAttribute("attribute");
use cssSelector for best result.
or else try the following xpath
//div[contains(#class, 'a')]
If you want attribute of div.a with it's descendant span which contains text something, try as below :-
driver.findElement(By.xpath("//div[#class = 'a' and descendant::span[text() = 'Text Example']]")).getAttribute("attribute");
Hope it helps..:)
So if I have this piece of code
<body>
<div class="red">
<a href="http://www.example.com>Example</a>
</div>
</body>
I know that I want to get an element with the attribute "class" and value "red" but I don't know where is located.
If I used XPath, is this piece of code right?
dir = "http://www.domain.com"
doc = Nokogiri::HTML(open(url))
doc.xpath('.//*[class="red"]')
I'm just learning so I don't know if any of this is wrong. I can't make it work. Thanks.
Edit: Now it's working =)
doc.xpath('//*[#class="red"]')
Change class to #class. Remove the dot in the beginning. Then it will work.