java - What is the correct way to pass arguments to the JavascriptExecutor? -


i'm trying use javascriptexecutor code, involved passing in webelement , info it. getting errors, simplified down find problem.

string test = ((javascriptexecutor)driver).executescript("return arguments[0];", "macon").tostring();

that code won't run. it'll throw nullpointerexception. can avoid not trying access passed variable. doesn't seem matter pass; int, string, webelement, etc etc.

so what's wrong? can't see discrepancies between online examples , code, there's something. i'm using firefox webdriver, , selenium version 2.44.0

you need cast results string:

javascriptexecutor js = (javascriptexecutor) driver; string test = (string) js.executescript("return arguments[0];", "macon"); 

also, there compatibility issues between selenium 2.44 , firefox 35/36 affected javascript code execution:


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -