如何处理 javascript 执行程序的脚本超时以获取调用
how to handle script time out for javascript executer for fetch call
我正在使用 selenium java 脚本执行器执行下面的 java 脚本,我想 return 获取调用的响应并将其存储在 java 代码中的变量。
但是下面的代码显示脚本超时,有什么建议可以满足上述要求吗???
String location = "!async function(){\n" +
"let data = await fetch(\"https://raw.githubusercontent.com/IbrahimTanyalcin/LEXICON/master/lexiconLogo.png\")\n" +
" .then((response) => response.blob())\n" +
" .then(data => {\n" +
" return data;\n" +
" })\n" +
" .catch(error => {\n" +
" console.error(error);\n" +
" });\n" +
"\n" +
"console.log(data);\n" +
"return data;\n" +
"}();\n";
Object str = js.executeAsyncScript(location);
使用setTimeout()
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
How to useexecuteAsyncScriptmethodinorg.openqa.selenium.JavascriptExecutor
我不知道如何转义引号,但 javascript 应该是:
let url = "https://..."
fetch(url).then(r => r.blob()).then(arguments[0])
arguments[0]是回调,需要在30秒内调用否则超时
我正在使用 selenium java 脚本执行器执行下面的 java 脚本,我想 return 获取调用的响应并将其存储在 java 代码中的变量。 但是下面的代码显示脚本超时,有什么建议可以满足上述要求吗???
String location = "!async function(){\n" +
"let data = await fetch(\"https://raw.githubusercontent.com/IbrahimTanyalcin/LEXICON/master/lexiconLogo.png\")\n" +
" .then((response) => response.blob())\n" +
" .then(data => {\n" +
" return data;\n" +
" })\n" +
" .catch(error => {\n" +
" console.error(error);\n" +
" });\n" +
"\n" +
"console.log(data);\n" +
"return data;\n" +
"}();\n";
Object str = js.executeAsyncScript(location);
使用setTimeout()
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
How to useexecuteAsyncScriptmethodinorg.openqa.selenium.JavascriptExecutor
我不知道如何转义引号,但 javascript 应该是:
let url = "https://..."
fetch(url).then(r => r.blob()).then(arguments[0])
arguments[0]是回调,需要在30秒内调用否则超时