Here is the code I am working with:
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
// javascriptExecutor.executeScript("W.setOffer({offer: {kind: \"coupon\", title: \"Hello\", availability: " +
// "\"available\"}},{})");
String script =
"var aLocation = {}" +
"var aOffer = {}" +
"var aAdData = " +
"{ " +
"location: aLocation, " +
"offer: aOffer " +
" } " +
"var aClientEnv = " +
" { " +
" sessionid: “”, " +
" cookie: “”, " +
" “rtserver-id”: 1, " +
" lon: 34.847, " +
" lat: 32.123, " +
" venue: “”, " +
" venue_context: “”, " +
// AD-{"campaignId":8224,"offerId":4172}
// see Venue Context for more information.
" source: “”," + // One of the following (string) values: ADS_PIN_INFO,
// ADS_0SPEED_INFO, ADS_LINE_SEARCH_INFO,
// ADS_ARROW_NEARBY_INFO, ADS_CATEGORY_AUTOCOMPLETE_INFO,
// ADS_HISTORY_LIST_INFO
// (this field is also called “channel”)
" locale: “”" + // ISO639-1 language code (2-5 characters), supported formats:
// * en/he/fr/…
// * en-GB/pt-BR/en_GB/pt_BR
// * es-419/es_419
" } " +
"W.setOffer(aAdData, aClientEnv);";
javascriptExecutor.executeScript(script);
}
The code fails at the executeScript
phase.
org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected token var
(Session info: chrome=42.0.2298.0)
(Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 18 milliseconds
I have double-checked the script. Is there something crucial that I might be overlooking?
Is it not permissible to use the var
keyword to store an element?
var aLocation = {}
var aOffer = {}
var aAdData = {
location: aLocation,
offer: aOffer
}
var aClientEnv = {
sessionid: “”,
cookie: “”,
“rtserver - id”: 1,
lon: 34.847,
lat: 32.123,
venue: “”,
venue_context: “”,
source: “”,
locale: “”
}
W.setOffer(aAdData, aClientEnv);