Can't extract data using xpath - xpath

I can't extract the address out of the element I'm pasting below. It's the "br" tag which is putting a barrier for the data to get extracted.
<div class="secondary-attributes">
<span aria-hidden="true" data-hovercard-id="1" style="width: 18px; height: 18px;" class="icon icon--18-info icon--size-18 icon--currentColor yloca-info">
<svg class="icon_svg">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#18x18_info"></use>
</svg>
</span>
<span class="neighborhood-str-list">
Nob Hill </span>
<address>
700 Bush St<br>San Francisco, CA 94108
</address>
<span class="offscreen">Phone number</span>
<span class="biz-phone">
(415) 391-5008
</span>
</div>
I tried XPath like :
//div[#class="secondary-attributes"]/#address

With //div[#class="secondary-attributes"]/#address you're trying to get attribute address from div while you need to get text content of address child element:
//div[#class="secondary-attributes"]/address/text()
If you need to extract "700 Bush St" and "San Francisco, CA 94108" separately, you might need to specify index:
//div[#class="secondary-attributes"]/address/text()[1]
for "700 Bush St" or
//div[#class="secondary-attributes"]/address/text()[2]
for "San Francisco, CA 94108"

Related

Error trying to get data using XPath on Google IMPORTXML function

I am trying to find the XPath to get 5 values of the following website: https://plataforma.penserico.com/dashboard/cp.pr?e=TRPL4
I want the values 7,59 2,04 1,81 7,60 7,59
For the first value I tried this command but I get #N/A:
=IMPORTXML("https://plataforma.penserico.com/dashboard/cp.pr?e=TRPL4";"//*[#id='j_idt104:0:j_idt109:1:chartPanel0']/div/span[1]")
The piece of HTML is like below:
<span id="j_idt104:0:j_idt109:1:chartPanel0">
<div class="c--anim-btn" style="color: #5DADE2;">
<span class="c-anim-btn">
7,59
</span>
<span>
<div style="font-size: 12px !important;">
<div style="width: 90%; left: 5%; position:relative;line-height:2em;white-space: nowrap;">
<div style="width:50%;float:left"><label class="idtri">1T:</label>2,04</div>
<div style="width:50%;float:right"><label class="idtri">2T:</label>1,81</div>
</div>
<div style="width: 90%; left: 5%; position:relative;line-height:2em;white-space: nowrap;">
<div style="width:50%;float:left"><label class="idtri">3T:</label>7,60</div>
<div style="width:50%;float:right"><label class="idtri">4T:</label>7,59</div>
</div>
</div>
</span>
</div></span>
What could be the second paramenter to get the values I want?
Thank you
You have to fix your XPath with the following one to get the values :
//tr[.//span[.='P/L']]/td[2]//text()[parent::span[#class='c-anim-btn'] or parent::div][normalize-space()]
Output (formula in C4):
EDIT : Individual XPath :
//tr[.//span[.='P/L']]/td[2]//text()[parent::span[#class='c-anim-btn']]
(//tr[.//span[.='P/L']]/td[2]//text()[parent::div][normalize-space()])[1]
(//tr[.//span[.='P/L']]/td[2]//text()[parent::div][normalize-space()])[2]
(//tr[.//span[.='P/L']]/td[2]//text()[parent::div][normalize-space()])[3]
(//tr[.//span[.='P/L']]/td[2]//text()[parent::div][normalize-space()])[4]

Get what's behind "Location:" with XPath

I try to get France that's behind Location:
I wrote this XPath: //div[#class="vevent"]/div/div/span[text()="Location: "]. That's how far I came, but how to I get France that comes after.
<div class="vevent">
<div style="float:left; padding-right: 20px;"><img alt="I’M YOUR DJ New Year Edition / 5th Anniversary Celebration" src="https://res.cloudinary.com/latindancecalendar/image/fetch/w_350,h_350/https%3A%2F%2Fi1.wp.com%2Flatindancecalendar.com%2Fdancecal%2Fwp-content%2Fuploads%2F50015933_2182298412088647_1361353647551676416_o.jpg%3Fresize%3D350%252C350%26ssl%3D1" width="200" height="200" scale="0"></div>
<div style="float:left;"><span class="dtstart"><span class="value-title" title="2019-12-27"></span></span><span><b>Friday, 27 December 2019</b></span>
<div><span class="location">Château Lafitte Yvrac ( Bordeaux ) - SCEA Chateau LAFITTE 41 Chemin du Loup, 33370 Yvrac, Aquitaine, France</span></div>
<div>Hosted by <b>I’M YOUR DJ – New Year Edition – Bordeaux</b></div>
<div><span>Location: </span>France</div>
<div><span class="eventpostviews"><i class="fas fa-map-marker-alt" style="padding-right: 5px;"></i>Map | 175 Views | <a style="color:#8F8F8F;" href="https://latindancecalendar.com/report-a-listing/?listing-url=https%3A%2F%2Flatindancecalendar.com%2Ffestivals%2Fim-your-dj-new-year-edition-5th-anniversary-celebration-2019%2F" rel="nofollow"><i class="fas fa-times" style="padding-right: 3px;font-size: 11px;"></i>Report Problem</a></span></div>
<div style="padding-top: 20px;">
<iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Flatindancecalendar.com%2Ffestivals%2Fim-your-dj-new-year-edition-5th-anniversary-celebration-2019%2F&width&layout=button_count&action=like&size=large&show_faces=false&share=false&height=35&appId=532405580227185" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:35px;" allowtransparency="true"></iframe>
</div>
</div>
</div>
This should work:
//div[#class="vevent"]/div/div[span = "Location: "]/text()
It selects the div that contains a span with the string value "Location: " and then retrieves the text node directly within that div.
Better give the html in script. Not picture.
And I guess you can use:
'''
following::text()
'''

Xpath grab div contents based on span class

<div class="accrd-row">
<h3 class="ui-helper-reset ui-accordion-header ui-corner-top ui-accordion-header-collapsed ui-corner-all ui-state-default ui-accordion-icons" role="tab" id="ui-id-1" aria-controls="ui-id-2" aria-selected="false" aria-expanded="false" tabindex="0"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><span class="icon icon-ki-act-panda"></span>Outdoor Activities</h3>
<div class="accrd-detail ui-accordion-content ui-corner-bottom ui-helper-reset ui-widget-content" id="ui-id-2" aria-labelledby="ui-id-1" role="tabpanel" aria-hidden="true" style="display: none;">Need to grab this text here</div>
</div>
I am trying to grab the text:
Need to grab this text here
Based on that the span above has the word "panda" in it. I know it is something like:
//span/#class[contains(.,'panda')]/following-sibling::a/div
But I cannot seem to get this to pick up the text.
You need to go back to the parent of span since the div you are looking for is a sibling of h3 not span.
There is probably a nicer way to do it but this is working for me to get the div element you need:
//h3//span[contains(#class, 'panda')]/parent::h3/following-sibling::div

xpath preceding-sibling select

could someone give me a hint how to get "Some text1" in dependence on svg class="svg svg-goal"?
This works
$x("//br/../preceding-sibling::strong/a")
This does not work
$x("//svg[#class='svg svg-goal']/../preceding-sibling::span/strong/a")
Hier HTML code
<span class="event-p-name">
<strong>
Some text1
</strong>
<small>
<br>Some text2</br>
</small>
</span>
<span class="event-type">
<svg class="svg svg-goal">
<use xlink:href="/public/themes/svg/symbol-defs.svg#football"></use>
</svg>
</span>
Thanks
For <svg> element (and its child elements) you need to use //*[name()='svg'] syntax. Try below:
//*[name()='svg' and #class='svg svg-goal']/../preceding-sibling::span/strong/
Try this
//svg[#class='svg svg-goal']/preceding::span/strong/a
Result
Some text1

Identifying previous items using xpath in Selenium IDE

I want to check the checkbox based on the value in the text input labeled 'Field' I have tried the following:
<tr>
<td>check</td>
<td>/label[text()="Field"]/../input[#value="6 1012 49817"]/preceding-sibling::label[text()="Private"]/../input</td>
<td></td>
</tr>
Here is the HTML:
<div class="wdg colShwHdeCls" id="divFormFieldPrivate-0" style="width: 82px;">
<input id="FormFieldPrivate-0" name="FormFieldPrivate-0" title="" style="" class="wdg colShwHdeCls" type="checkbox">
<label for="FormFieldPrivate-0">Private</label>
</div>
<div class="csLineBreak"> </div>
<div class="acI fldWd100 wdg colShwHdeOpn" id="divFormFieldId-0"><label for="FormFieldId-0">Field<a class="aut" title="Show selection list"></a>
<a style="display: inline-block; opacity: 0.0118143;" href="field/view?FieldId=" title="View this Field" class="acOptVw acLb acI"></a>
<a style="display: inline-block; opacity: 0.0118143;" href="field/edit?FieldId=" class="acEd acLb acI" title="Edit this Field"></a>
<a style="display: inline-block; opacity: 0.0118143;" href="field/add?FieldId=" class="acAd lightbox acI" title="Add a new Field"></a>
</label>
<br>
<span style="display:none;" id="FormFieldId-0-Old">6 1012 49817</span>
<input id="FormFieldId-0" name="FormFieldId-0" value="11955" type="hidden">
<input autocomplete="off" id="FormFieldId-0-Dsp" title="type three or more characters to see selection list" class="wdg csAutCpl csAutCplFld ui-autocomplete-input" value="6 1012 49817" type="text">
<span class="ui-helper-hidden-accessible" aria-live="polite" role="status"></span>
</div>
Suggestions are welcome thanks ;-)
This is one possible way. First part of the XPath supposed to find the div element containing label with certain text ("Field" in this case) and input with certain value attribute :
//div[label[normalize-space(text())="Field"] and input[#value="6 1012 49817"]]
From the above div, find preceding sibling div containing label with text equals "Private", then get the input child element of that div :
/preceding-sibling::div[label[text()="Private"]]/input
So the entire XPath will look about like this :
//div[label[normalize-space(text())="Field"] and input[#value="6 1012 49817"]]/preceding-sibling::div[label[text()="Private"]]/input
xpathtester.com demo

Resources