我尝试在Selenium Web驱动程序中运行以下代码,但显示一些错误
密码是
WebElement w=driver.findElement(By.xpath("//*[@class='tab']"));
JavascriptExecutor js=(JavascriptExecutor) driver;`
js.executeScript("arguments[0].setAttribute('disable,'');",w);
错误为:
org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token
(Session info: chrome=59.0.3071.115)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.10240 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 463 milliseconds
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'DESKTOP-AQGDP71', ip: '192.168.2.25', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\SEKAR\AppData\Local\Temp\scoped_dir3836_13558}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.115, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 9568bb1918bcb9bfdfbc4afab2cf8294
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:540)
at `enter code here`stepdefinition.Cheking`enter code here`.search_with_text_and_check_listed_corectly(Chek`enter code here`ing.ja`enter code here`va:57)
at ?
用文本搜索时,检查列表是否正确(检查功能:7)
3条答案
按热度按时间hi3rlvi21#
你是丢失引号.可能是一个打字错误.
suzh9iv82#
我也面临着这个问题,在我的情况下,我使用:
如果要发送的数据中有单引号,**它需要在前面有反斜杠。**您可以使用以下java代码:
现在,它将以“5'7”而不是“5'7”发送数据。
yrefmtwq3#
正如穆尔提所说的:您缺少引号
如果你想使用selenium(python)和javascript来填充python的文本输入,最好使用
json.dumps(python_str)
注意json转储添加了引号,所以当你在javascript中使用字符串时,不要把它放在引号之间
js将像这样接收它:
'test.innerText = ""hello world"";
,您将看到错误sys:javascript错误:意外的标识符hello
如果使用单引号,则字符串中将包含双引号
因此,要解决此问题,请不要添加单引号或双引号,因为已经添加了
json.dumps
并使用HTML实体代码替换所有qoutes