Reputation: 10062
I am using CasperJS to do some browser automation. Now I have an array, which contains text that can be found on some buttons that are randomly generated on the page. I pick a random button, and assign it to a variable, and now I want to find it, and click it based on its text value.
I am having trouble building the XPath selector.
so:
var pickedButton = 'my button text';
this.click(x('//*[text()="my button text"]'));
Can anyone point out how I can pass in a variable, instead of a string?
Upvotes: 0
Views: 561
Reputation: 10062
Just used string concatenation to build the selector:
var selector = "\'//*[text()=\"" + pickedButton + "\"]\'";
this.click(x(selector));
Upvotes: 1