gpt4 book ai didi

javascript - 线程 "main"org.openqa.selenium.WebDriverException : unterminated string literal 中出现异常

转载 作者:行者123 更新时间:2023-12-03 12:08:20 26 4
gpt4 key购买 nike

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FindElementsUsingJS {

static WebDriver driver= new FirefoxDriver();


public static void main(String[] args) {
driver.get("http://scripting.jdpoweronline.com/mrIWeb/mrIWeb.dll?I.Project=T1_QTYPE&i.test=1");
// get HTML of above URL
String scriptContents = "return '<html>'+$( 'html' ).html()+'</html>'";
String contentss = (String) ((JavascriptExecutor) driver).executeScript(scriptContents);

// get DOM obj
String content="return $.parseHTML('"+contentss+"')";
System.out.println(((JavascriptExecutor) driver).executeScript(content));
//System.out.println(contentss);
}
}

嗨,我想做以下事情1.使用JavascriptExecutor获取contents var中的HTML文档(工作正常)2. 创建收集的 HTML 的 DOM 对象(不起作用异常(exception))。3. 使用预定义的方法获取 DOM 元素。

我遇到以下异常

>  Exception in thread "main" org.openqa.selenium.WebDriverException: unterminated string literal
Command duration or timeout: 14 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'ATMECSINDT-068', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.0-37-generic', java.version: '1.7.0_55'
Session ID: c3857c80-97e6-4955-9323-d1418b237441
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=30.0}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)
at publicc.FindElementsUsingJS.main(FindElementsUsingJS.java:27)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: unterminated string literal
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'ATMECSINDT-068', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.0-37-generic', java.version: '1.7.0_55'
Driver info: driver.version: unknown
at <anonymous class>.handleEvaluateEvent(http://scripting.jdpoweronline.com/

最佳答案

您为 scriptContents 提供的字符串文字在我看来是错误的。 ' 位于 + 之前,而不是 + 之后。

这是正确的:

String scriptContents = "'<html>'+$( 'html' ).html()+'<html>'";

希望有帮助。

关于javascript - 线程 "main"org.openqa.selenium.WebDriverException : unterminated string literal 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25079449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com