JavaScript executor not working with Selenium interaction

664 views
Skip to first unread message

Yuriy

unread,
Jun 22, 2015, 9:09:28 PM6/22/15
to galen-f...@googlegroups.com
Hello!

Before I execute the test, I run the following code from init.js file as Selenium interaction:

driver.findElement(By.id("truste-consent-button")).click();
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,400)");

On the first line I locate and click the button to accept use of cookies (required by the site under test)
On the second line I try to scroll the window down by 400 pixels.

My test file in Galen is:

Ads: Site Home
    ${base_url}/ 768x1024
        run init.js        
        wait 20s
        check home.spec

But the init.js fails on the second line with the following error message:

EvaluatorException: missing ) in parenthetical (init.js#2)
org.mozilla.javascript.EvaluatorException: missing ) in parenthetical (init.js#2) at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77) at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:64) at org.mozilla.javascript.Parser.addError(Parser.java:188) at org.mozilla.javascript.Parser.addError(Parser.java:166) at org.mozilla.javascript.Parser.reportError(Parser.java:223) at org.mozilla.javascript.Parser.reportError(Parser.java:217) at org.mozilla.javascript.Parser.mustMatchToken(Parser.java:388) at org.mozilla.javascript.Parser.mustMatchToken(Parser.java:378) at org.mozilla.javascript.Parser.parenExpr(Parser.java:2862) at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2785) at org.mozilla.javascript.Parser.memberExpr(Parser.java:2418) at org.mozilla.javascript.Parser.unaryExpr(Parser.java:2316) at org.mozilla.javascript.Parser.mulExpr(Parser.java:2241) at org.mozilla.javascript.Parser.addExpr(Parser.java:2225) at org.mozilla.javascript.Parser.shiftExpr(Parser.java:2206) at org.mozilla.javascript.Parser.relExpr(Parser.java:2181) at org.mozilla.javascript.Parser.eqExpr(Parser.java:2153) at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:2142) at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:2131) at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:2120) at org.mozilla.javascript.Parser.andExpr(Parser.java:2109) at org.mozilla.javascript.Parser.orExpr(Parser.java:2098) at org.mozilla.javascript.Parser.condExpr(Parser.java:2062) at org.mozilla.javascript.Parser.assignExpr(Parser.java:2033) at org.mozilla.javascript.Parser.expr(Parser.java:2012) at org.mozilla.javascript.Parser.statementHelper(Parser.java:1039) at org.mozilla.javascript.Parser.statement(Parser.java:901) at org.mozilla.javascript.Parser.parse(Parser.java:540) at org.mozilla.javascript.Parser.parse(Parser.java:502) at org.mozilla.javascript.Context.compileImpl(Context.java:2350) at org.mozilla.javascript.Context.compileReader(Context.java:1296) at org.mozilla.javascript.Context.compileReader(Context.java:1268) at org.mozilla.javascript.Context.evaluateReader(Context.java:1107) at net.mindengine.galen.javascript.GalenJsExecutor.eval(GalenJsExecutor.java:98) at net.mindengine.galen.suite.actions.GalenPageActionRunJavascript.execute(GalenPageActionRunJavascript.java:58) at net.mindengine.galen.runner.GalenPageRunner.executeAction(GalenPageRunner.java:77) at net.mindengine.galen.runner.GalenPageRunner.run(GalenPageRunner.java:69) at net.mindengine.galen.runner.GalenBasicTestRunner.runTest(GalenBasicTestRunner.java:71) at net.mindengine.galen.tests.GalenBasicTest.execute(GalenBasicTest.java:53) at net.mindengine.galen.TestRunnable.runTest(TestRunnable.java:68) at net.mindengine.galen.TestRunnable.run(TestRunnable.java:94) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 

What's wrong with my init.js code? I'm trying to use JS code from within WebDriver to scroll the page. Or is there a better solution?

Ivan Shubin

unread,
Jun 23, 2015, 3:31:51 AM6/23/15
to galen-f...@googlegroups.com
Hi,

the second line looks more like a Java code. In JavaScript you don't care about the types so you don't have to cast objects to specific types to get their methods. Just use this:


driver
.findElement(By.id("truste-consent-button")).click();
driver
.executeScript("window.scrollBy(0,400)");



Yuriy

unread,
Jun 23, 2015, 6:44:48 AM6/23/15
to galen-f...@googlegroups.com
Thanks! It works!

Reply all
Reply to author
Forward
0 new messages