简体   繁体   中英

Selenium + C#: ExecuteAsyncScript not working

I'm trying to run javascript through Selenium driver. The executeAsyncScript argument gives the exception that input string is not in correct format. The javascript is in the path provided. The javascript function is actually an onclick that does not take any parameters but returns a value that I want to get for further computation.

 Driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
           var js = Driver as IJavaScriptExecutor;
     var formobject = js.ExecuteAsyncScript(
                           "var callback = arguments[0];"
                         + "var params = arguments;"
                         + "require(['Recruiting/Modules/CandidateProfile'],function(onPrint){"
                         + "onPrint("
                         + ",callback"
                         + ");});"
                     );

I think your javascript is syntacticly incorrect . If you would omit the quotes, you would get:

var callback = arguments[0];
var params = arguments;
require(['Recruiting/Modules/CandidateProfile'],function(onPrint){
onPrint(
,callback
);});

See the , after the onPrint and before the callback .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM