nknown错误:Runtime.evaluate抛出异常:SyntaxError:意外的标记变量 [英] nknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected token var
本文介绍了nknown错误:Runtime.evaluate抛出异常:SyntaxError:意外的标记变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码:
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);
}
但它在 executeScript $ c上失败$ c>
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
这是脚本。我错过了什么吗?
here is the script. Am I missing something?
我不能用 var
来保存元素吗?
cannot I use var
to save 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);
推荐答案
问题在于行连接。
此
String script =
"var aLocation = {}" +
"var aOffer = {}" +
"var aAdData = " +
"{ " +
"location: aLocation, " +
"offer: aOffer " +
" } "
与以下内容相同:
String script =
"var aLocation = {}var aOffer = {}var aAdData = { location: aLocation, offer: aOffer } "
哪个是无效的jsavascript。您可以在每个var之间使用新行或;
Which isn't valid jsavascript. you can either use new lines or ;
between each var
这篇关于nknown错误:Runtime.evaluate抛出异常:SyntaxError:意外的标记变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文