xpath preceding-sibling select - xpath

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

Related

xpath retrieve element that occur after parent element

I need to click on the element that appears after <span class="clientadress">
It can be either <div class="homephone"> or <input type="text">.
I try xpath /following:: or /child:: but it doesn't work.
Is it possible to do something like //following::(div or input)
Example of element order:
<span class="client">
<span class="clientadress">
<div class="homephone">
</span>
or
<span class="client">
<span class="clientadress">
<input type="text">
</span>
Try using
//span[#class="clientadress"]/(following-sibling::div | following-sibling::input)
and see if it works.
Try-Xpath in Firefox gives better results sometimes:
https://addons.mozilla.org/nl/firefox/addon/try-xpath/?utm_source=addons.mozilla.org&utm_medium=referral&utm_content=search
Jack gave me an idea and next is working for me: //following-sibling::*
Thank you all

select div(text) without span xpath

<div class="filters-list-item-content" xpath="4">
<span class="font-500">
Rodzaj konferencji:
</span>
Warsztaty
</div>
<div class="filters-list-item-content" xpath="5">
<span class="font-500"></span>
POH
</div>
I have 6 xpaths and try select all div(text) without text in span I try
//div[#class='filters-list-item-content']/*[not(.//span)]
//div[#class='filters-list-item-content']/SPAN[not(*)]
but it is select only text in span :(
If I understand you correctly, this is what you are looking for:
//div[#class='filters-list-item-content']/text()
Output:
Warsztaty
POH

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

Ruby Selenium Web Driver: How to find child element by class name matching substring

Am a novice selenium programmer please help me with this...
I have below html and am trying to find svg child element by class name matching substring deleteIcon in below html
<div class="result-controls">
<div class="attachment">
<li class="add-attachment-button-column"><a><button>ADD ATTACHMENTS</button></a></li><input type="file" multiple="" style="display: none;">
</div>
<li class="sign-button-column"><button>SIGN</button></li>
<li class="draft-button-column"><a><button>DRAFT</button></a></li>
<li class="delete-column"> <svg class="glyphicon-trash deleteIcon" viewBox="0 0 100 100"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#trash"></use></svg> </li>
</div>
I am trying to find svg element class matching 'deleteIcon' (row variable has above html)
row.find_element(:xpath => "./li/a/svg[contains(#class,'deleteIcon')]")
but am getting below exception
*** Element info: {Using=xpath, value=./li/a/svg[contains(#class,'deleteIcon')]} (org.openqa.selenium.NoSuchElementException)
can anyone help me with this in Ruby using selenium web driver?
You cannot use svg as a tag name in xpath expression.Try using below xpath,
"./li/a/*[name()='svg'][contains(#class,'deleteIcon')]"

Need span title in Xpath

I need span title text (RS_GPO) as my xpath output
Here is code:
<TD id="celleditableGrid07" nowrap="nowrap" style='padding:0px;' >`
<DIV class='stacked-row'>
<span id="form(202567).form(TITLE).text" >
<span title='RPS_AEM3'>RPS_AEM3</span>
</span>
</DIV>
<DIV class='stacked-row-bottom'>
<span id="form(202567).form(CONTENT).text" >
<span title='RS_GPO'>RS_GPO</span>
</span>
</DIV>
My intention for xpath is I want catch text “RS_GPO” in to a variable.
Because this is system generated text.
Thanks in Advance.
//span[#title='RS_GPO']
OR
//div[#class='stacked-row-bottom']/span[#id='form(202567).form(CONTENT).text']/span[#title='RS_GPO']
//span[contains(#id,'form(CONTENT).text')]/span
If you want the content of the title attribute instead of the element's text content, then:
//span[contains(#id,'form(CONTENT).text')]/span/#title

Resources