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.