combine two xpath expretion with the same prefix - xpath

I'm trying to find some way to merge the result of two xpath queries with the same prefix.
Say: /inventory/product/itemNumber | /inventory/product/itemName
I'm looking for something like /inventory/product/(itemNumber | itemName) (the order of the output is irreverent for me).
Basically, I'm trying to find a way not to write the long prefix twice.
Thanx!

The way to accomplish this is the following:
/inventory/product/*[self::itemNumber or self::itemName]

Related

How to use wildcard attribute name and contains()?

In my problem I search for elements that have an example structure like:
<ngc-product-card ng-reflect-signup-type="comprehensive">
Since the elements may have the comprehensive value stored in another attribute, say:
<new-ngc-product-card data-label="comprehensive signup">
hence I would like to use a wildcard-attribute-name search and also apply the contains() function like:
//*[contains(#*,"comprehensive")]
which doesn't work
What does work is
//*[#*="comprehensive"]
Is there any way to use both '#*' and 'contains()' ?
This should do.
//*[#*[contains(., "comprehensive")]]

rx, looking for something like takeUntilMap

Im trying to achieve following behaviour:
//----A--A----A--|-----------------------------------streams
//--B------------B---B--B-------------------------------
//----A--A----A--B---B--B-----------------------------output
in other words: I need to complete A-stream by B-stream and still be able to consume first B item, but I cant find the way to do that.
example jsfiddle.net/dismedia/qbyy5cvs we have numbers$ and operators$, I need to scan numbers until operator appears
You could use the following:
Observable.concat(obsA.takeUntil(obsB), obsB)
.subscribe(...)

Xamarin UI Testing: search for elements "marked" with a string ignoring case and searching substring

Currently, when I use app.Tap I have to give it the exact string.
I want to do something like app.Tap("sstring") and still match elements marked with e.g. "somessting", "someSStRing", etc.
is it possible to have that somehow? it sounds like a simply thing, but I couldn't find a way to do it and it's surprising that there is no option to make it behave that way.
Have you tried doing it via the function overload and specifying the id?
app.Tap(e => e.Id("sstring"));
Marked searches many properties on each element to return any matches.

XPATH - how to use multiple operators on one query

I am scraping a web URL that looks like this:
www.example.com/pages/popup/popup_report_review.aspx?bikeReviewID=6582049&PageTypeID=9&width=900&height=500
I only want the ID number from it. I tried to run this query first to start the parsing after the "=" and it works perfectly:
normalize-space(substring-after(//a[#id='webpage_url']/#href, '='))
So now I have: 6582049&PageTypeID=9&width=900&height=500
I now want to run another query to just leave me with the ID number so I think this is the one:
substring(//a[#id='webpage_url']/#href,1,7)
This leaves me with only 7 characters. They both work perfectly independently, but I cannot get them to run together. I tried using 'and' but that returns me a number 1.. This is what I did:
normalize-space(substring-after(//a[#id='webpage_url']/#href, '=')) and substring(//a[#id='webpage_url']/#href,1,7)
Does anyone know how I can combine both queries or is there a better way to get this ID? Thanks in advance doe any pointers.
I should use this query:
substring-before(substring-after(//a[#id='webpage_url']/#href, '='), '&')

XPath concat multiple nodes

I'm not very familiar with xpath. But I was working with xpath expressions and setting them in a database. Actually it's just the BAM tool for biztalk.
Anyway, I have an xml which could look like:
<File>
<Element1>element1<Element1>
<Element2>element2<Element2>
<Element3>
<SubElement>sub1</SubElement>
<SubElement>sub2</SubElement>
<SubElement>sub3</SubElement>
<Element3>
</File>
I was wondering if there is a way to use an xpath expression of getting all the SubElements concatted? At the moment, I am using:
/*[local-name()='File']/*[local-name()='Element3']/*[local-name()='SubElement']
This works if it only has one index. But apparently my xml sometimes has more nodes, so it gives NULL. I could just use
/*[local-name()='File']/*[local-name()='Element3']/*[local-name()='SubElement'][0]
but I need all the nodes. Is there a way to do this?
Thanks a lot!
Edit: I changed the XML, I was wrong, it's different, it should look like this:
<item>
<element1>el1</element1>
<element2>el2</element2>
<element3>el3</element3>
<element4>
<subEl1>subel1a</subEl1>
<subEl2>subel2a</subEl2>
</element4>
<element4>
<subEl1>subel1b</subEl1>
<subEl2>subel2b</subEl2>
</element4>
</item>
And I need to have a one line code to get a result like: "subel2a subel2b";
I need the one line because I set this xpath expression as an xml attribute (not my choice, it's specified). I tried string-join but it's not really working.
string-join(/file/Element3/SubElement, ',')
/File/Element3/SubElement will match all of the SubElement elements in your sample XML. What are you using to evaluate it?
If your evaluation method is subject to the "first node rule", then it will only match the first one. If you are using a method that returns a nodeset, then it will return all of them.
You can get all SubElements by using:
//SubElement
But this won't keep them grouped together how you want. You will want to do a query for all elements that contain a SubElement (basically do a search for the parent of any SubElements).
//parent::SubElement
Once you have that, you could (depending on your programming language) loop through the parents and concatenate the SubElements.

Resources