question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to make dynamic xpath calls

See original GitHub issue

Hi,

I’m using the following xpath expression to retrieve some node values from an XML.

* def sbsKey = get response /Envelope//resortID[text()='0450']/following-sibling::accomodationProducts[1]//*[local-name()='unit'][1]//sbsKey
* print "The season code is "+sbsKey

My question is - How do I make the the following section of the xpath dynamic

[//resortID[text()='0450']]

I was hoping something like this would solve the purpose, but it doesn’t -

* def fetchedResortID = get response /Envelope//resortID[1]
* print fetchedResortID

* def sbsKey = get response "/Envelope//resortID[text()='"+fetchedResortID+"']/following-sibling::accomodationProducts[1]//*[local-name()='unit'][1]//sbsKey"
* print "The season code is "+sbsKey

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pmijarcommented, May 23, 2018

Thanks Peter. I did figure out this issue. I converted the response object to xml through type conversion and then applied the xpath expression.

Works fine now

Regards, Prashanth Email: Prashanth.Mijar@gmail.com

On May 22, 2018, at 10:42 PM, Peter Thomas notifications@github.com wrote:

@pmijar I need a working example. please follow the instructions here and log a separate issue, thanks: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

1reaction
ptrthomascommented, Mar 19, 2018

actually this is a gap. where we have a way to do this for jsonPath so I’m treating this as a feature request. I think you can use this work-around for now (works only for string values, not XML chunks).

* def xpath = "/Envelope//resortID[text()='" + fetchedResortID + "']/following-sibling::accomodationProducts[1]//*[local-name()='unit'][1]//sbsKey
* def sbsKey = karate.get(xpath)
Read more comments on GitHub >

github_iconTop Results From Across the Web

XPath Functions For Dynamic XPath In Selenium
This Tutorial Explains the Usage of XPath Functions in Identifying the Elements With Examples: Before automating any website is necessary to ...
Read more >
How to write Dynamic XPath in Selenium - Learn Automation
Yes, you can use array for that. Take all locators wrt browse button inside an array and call its click action based on...
Read more >
Dynamic XPath In Selenium WebDriver A Complete Guide
Dynamic XPath is used to locate exact attribute or decrease the number of matching nodes/result from a webpage and following XPath expressions ...
Read more >
Dynamic XPath in Selenium using Different Approaches
Do you know how to write Dynamic xpath in Selenium Webdriver? In this video, we will mainly discuss XPath different methods which will...
Read more >
How To Write Dynamic XPath In Selenium WebDriver
In this XPath in Selenium Tutorial, we will learn the different ways of writing Dynamic XPath in Selenium WebDriver.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found