Skip to content
Advertisement

how to handle script time out for javascript executer for fetch call

I am executing the below javascript using selenium java script exceuter, I want to return the response fromt the fetch call and want to store it in java variable in code. But below code is showing script time out, any suggestions how can I achive above requirements ???

 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);

Advertisement

Answer

I’m not how to escape the quotes but the javascript should be:

let url = "https://..."
fetch(url).then(r => r.blob()).then(arguments[0])

arguments[0] is the callback, it needs to call that within 30 seconds or the timeout happens

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement