javascript - org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or un

I am trying to run below code in Selenium web driver but its shows some errorThe code isWebElement w=dr

I am trying to run below code in Selenium web driver but its shows some error

The code is

    WebElement w=driver.findElement(By.xpath("//*[@class='tab']"));

    JavascriptExecutor js=(JavascriptExecutor) driver;`

    js.executeScript("arguments[0].setAttribute('disable,'');",w);

The error is:

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 ?

When search with text and check listed corectly(Cheking.feature:7)

I am trying to run below code in Selenium web driver but its shows some error

The code is

    WebElement w=driver.findElement(By.xpath("//*[@class='tab']"));

    JavascriptExecutor js=(JavascriptExecutor) driver;`

    js.executeScript("arguments[0].setAttribute('disable,'');",w);

The error is:

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 ?

When search with text and check listed corectly(Cheking.feature:7)

Share Improve this question edited Jul 14, 2017 at 6:24 piet.t 11.9k21 gold badges44 silver badges55 bronze badges asked Jul 14, 2017 at 6:01 SekarSekar 211 gold badge1 silver badge2 bronze badges 1
  • are we having an attribute disable for webelement w? – santhosh kumar Commented Jul 14, 2017 at 6:36
Add a ment  | 

3 Answers 3

Reset to default 1

you are missing quotes. may be a typo.

js.executeScript("arguments[0].setAttribute('disable','');",w);

I was also facing this issue, in my case I was using:

element.sendKeys("5'7");

If you have single quote in the data to be sent, it needs to have back-slash before it. You can use following java code:

String text = "5'7";
text = text.replace("'", "\\'");
element.sendKeys(text);

Now, it will send the data as "5'7" instead of "5'7".

the issue as Murthi said: you are missing quotes

incase you want to use selenium (python) with javascript to fill input with text from python it's better to use json.dumps(python_str)

and note json dumps add quotes so when you use the string in javascript do not put it between quotes

'test.innerText = "{}";'.format(json_dumps(python_str))

js will receive it like this: 'test.innerText = ""hello world""; and you will see error sys :

javascript error: Unexpected identifier hello

if you used single quote you will have double quotes in string

so to solve this issue not add quotes single or double because json.dumps added already

"test.innerText = {};".format(json_dumps(python_str))

and replace all qoutes with HTML entity codes

python_str = python_str.replace("'", "'").replace('"', """).replace('`', '`')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744898648a4599846.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信