I have a product listing page and from there I want to select a product randomly to navigate to a product details page.
I want to use XPath using Javascript to extract the href URL and then use that value as part of the next transaction for navigation.
I am getting an error:
ReferenceError: "document" is not defined. (Script=script;Line=15)
My code:
var products = document.evaluate('count(//div[@class="details"])', document, null,0, null ).numberValue;
var randomProduct = Math.floor(Math.random() * products) + 1;
var element = document.evaluate( "(//a[@class=\"name\"])[" + randomProduct + "]" ,document, null, 9, null ).singleNodeValue;
logger.debug(element.href);
var url = element.href;
context.variableManager.setValue("prodUrl",url);
I am very new to this. I know I am doing something wrong. Please advise.
Thanks.
You can't use "document.evaluate" since NeoLoad does not act as a real browser and you do not have access to the DOM of the page.
Can't you create a variable extractor using an XPATH method to randomly extract your product?
Open the Advanced panel of your request in the design section and from here you can create your variable extractor.
Nouredine was made best respondent
Nouredine answered
Praveen Kumar posted a new question