JavaScript
記事
IT・テクノロジー
実行
同期
driver.execute_script("同期処理;")
非同期
driver.set_script_timeout(タイムアウトの秒数)
driver.execute_async_script("非同期処理;")
driver.execute_async_script("""
const callback = arguments[arguments.length - 1];
処理
callback();
""")
※ タイムアウトの秒数のデフォルトは0秒なので必ず指定する
callbackを呼び出して非同期処理を完了する
引数
driver.execute_script("スクリプト;", 引数1, ...)
引数は arguments配列 でアクセスできる
ex) 引数1: arguments[0]
戻り値
戻り値 = driver.execute_script("return 値;")
非同期
戻り値 = driver.execute_async_script("""
const callback = arguments[arguments.length - 1];
処理
callback(値);
""")