1

I am trying to execute the following script in selenium

    result = driver.execute_script('let result; await axe.run().then((r)=> {result=r}); return result;')

But it is returning

javascript error: await is only valid in async function

I also tried doing

    result = @driver.execute_async_script('(async() => {return await axe.run();})();')

but it returned the following error

Selenium::WebDriver::Error::ScriptTimeoutError: script timeout: result was not received in 30 seconds

1 Answers1

1

If you want to use execute_async_script you need to call the passed callback function to tell the driver you are done, otherwise the driver does not recognize you are done and waits until timeout. The callback function is the last argument:

script = "
var callback = arguments[arguments.length - 1]; // this is the callback to call when you are done
axe.run().then((r)=> {callback(r)});
"
result = @driver.execute_async_script(script);

For a reference see

Payam V
  • 106
  • 4