robot framework execute javascript

I have this code to execute on robot framework:

${result}=   Execute JavaScript   window.document.evaluate("//div[@id='priceBandTableForm:priceBandBox_panel']/div/ul/li[1]/text()", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

The result is this:

${result} = None

I have tested the javascript code on chrome console and it works.

Any ideas of what I'm doing wrong?

Upvotes: 0

Views: 1052

Answers (3)

Ankit Bijlwan
Ankit Bijlwan

Reputation: 31

Use the execute javascript like mentioned below.

${textToCompare}=  Execute JavaScript     return document.evaluate('<Your Xpath here>', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;

Upvotes: 0

Sinta555
Sinta555

Reputation: 29

You probably forgot to add return before the JS ?

Upvotes: 1

I have resolved this by adding ".textContent" at the end, and "return" at the beginning.

${result}=   Execute JavaScript return   window.document.evaluate("//div[@id='priceBandTableForm:priceBandBox_panel']/div/ul/li[1]/text()", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;

Upvotes: 2

Related Questions