Any suggestions on resolving the "script timeout" issue while running a script using Python's SeleniumBase Library?

Recently starting to use Python, I am currently using Python's seleniumbase library to scrape a website and need to periodically run this fetch script. While experimenting, I encountered a script timeout error when the response time exceeded around 950 milliseconds. However, I could still see the fetch response in the browser's network tab. The code runs smoothly if the response delay is under 950 ms.

script = """
                return new Promise((resolve, reject) => {
                    var csrf = document.querySelector('meta[name="csrf-token"]').content;
                    var obj;
                
                    fetch("MyUrl", {
                        'headers': {
                            'accept': '/',
                            'accept-language': 'en-US,en;q=0.9',
                            'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
                            'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google       Chrome";v="116"',
                            'sec-ch-ua-mobile': '?0',
                            'sec-ch-ua-platform': '"Windows"',
                            'sec-fetch-dest': 'empty',
                            'sec-fetch-mode': 'cors',
                            'sec-fetch-site': 'same-origin',
                            'x-csrf-token': csrf,
                            'x-requested-with': 'XMLHttpRequest'
                        },
                        'referrer': 'MyUrl',
                        'referrerPolicy': 'strict-origin-when-cross-origin',
                        'body': 'consularid=3&exitid=1&servicetypeid=1&calendarType=2&totalperson=1',
                        'method': 'POST',
                        'mode': 'cors',
                        'credentials': 'include'
                    })
                        .then(res => res.text())
                        .then(data => {
                            obj = data;
                            resolve(obj);
                        })
                        .catch(error => {
                            reject(error);
                        });
                });
                """
            obj_variable = sb.execute_script(script)

An example of the error displayed is as follows:

Message: script timeout
  (Session info: chrome=116.0.5845.141)
Stacktrace:
    GetHandleVerifier [0x00007FF61E0352A2+57122]
    (No symbol) [0x00007FF61DFAEA92]
    (No symbol) [0x00007FF61DE7E25D]
    (No symbol) [0x00007FF61DEEF314]
    (No symbol) [0x00007FF61DED6FDA]
    (No symbol) [0x00007FF61DEEEB82]
    (No symbol) [0x00007FF61DED6DB3]
    (No symbol) [0x00007FF61DEAD2B1]
    (No symbol) [0x00007FF61DEAE494]
    GetHandleVerifier [0x00007FF61E2DEF82+2849794]
    GetHandleVerifier [0x00007FF61E331D24+3189156]
    GetHandleVerifier [0x00007FF61E32ACAF+3160367]
    GetHandleVerifier [0x00007FF61E0C6D06+653702]
    (No symbol) [0x00007FF61DFBA208]
    (No symbol) [0x00007FF61DFB62C4]
    (No symbol) [0x00007FF61DFB63F6]
    (No symbol) [0x00007FF61DFA67A3]
    BaseThreadInitThunk [0x00007FFAFEF07614+20]
    RtlUserThreadStart [0x00007FFB007C26B1+33]

I attempted to add a timeout to the script code without success; it is possible that my implementation was incorrect.

Answer №1

It seems like there is an issue with script timeouts while running the script in Selenium.

You mentioned attempting to add a timeout to the script, but it didn't resolve the issue as expected.

An alternative solution could be setting the timeout directly within the context of the Selenium script using the setTimeout function in JavaScript.

Another approach is utilizing execute_async_script to avoid waiting for script execution and preventing timeout errors.

Your code has been modified as follows:

script = """
// Code snippet here
"""

obj_variable = sb.execute_async_script(script)

I hope this resolves your problem. Feel free to reach out if you need further assistance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

utilize ng-include in angularjs to include a page

For some reason, I am having trouble including a file using ng-include. The file is supposed to be included when a button is pressed: <button type="submit" class="btn btn-primary" ng-click="getPartial()">Compare</button> This is the function ...

What measures can be taken to ensure that the input checkbox is not toggled by accidentally pressing

There's a checkbox input in a dropdown menu at the top of the page that is giving me some trouble. When I select an option by clicking on it, for some reason pressing the spacebar toggles it off and on. Clicking outside once doesn't correct it, I ...

ajax request encountered access denial when attempting to call wcf service

I have set up an Amazon EC2 instance and deployed my .NET web application on port 80, with the WCF service running on port 1212. While I can access both the application and service locally on the remote session, attempting to make Ajax requests over the i ...

Rendering basic JSON data from the console to an HTML page using Angular

I have been utilizing openhab for sensor monitoring. To extract/inject the items(things), sensor properties, and room configuration through a web interface, I am making use of openhab's REST queries which can be found here - REST Docs. Wanting to cre ...

assign a JSON key to a variable

Is there a way to use a variable as a JSON key in JavaScript? var chtid = "1234" firebase.database().ref().set ({chtid :"hi"}); In this case, chtid is the variable. I have attempted this method without success: var chtid = "1234" firebase.database().re ...

Filtering an Array in VueJS Based on User Input

Currently, I am working on a Vue.js application where my goal is to filter an array based on user input from a form. The issue I am facing is that the array named autocomplete is not being populated with visitors that match the query of the first name. T ...

Extracting <p> elements from a separate HTML file and cycling through them

I successfully created a website using only HTML, JavaScript, and jQuery without any server-side scripting or language. Within my website, I have a simple stream.html page that remains unstyled with no CSS formatting. <html> <head> </head& ...

Combining multiple arrays of arrays in JavaScript

I am dealing with an array that contains nested arrays. This particular array is called template template consists of 2 arrays, but the number can vary and there can be multiple levels of arrays within each one. Here's what I have attempted: const ...

How to Redirect a Webpage to the Same Tab in ASP.NET

I am currently using an asp.net hyperlink control to direct users to a web URL when the hyperlink is clicked. My goal is for the user to open a new tab, rather than a new window, when they click the hyperlink. If the user clicks the link again, I want th ...

Whenever I try to execute the command `electron .` in the electron-quickstart project, I immediately encounter an error within the

Upon successfully installing Electron, I attempted to run it using "electron" or "electron -v" commands. Unfortunately, I encountered an error while running it on Windows 10. C:\Windows\System32\electron-quick-start>electron -v modu ...

"Steady layout of grid for the navigation bar and

Currently, I am in the process of developing a control panel with the use of HTML and CSS. To structure the page, I opted for a grid layout. However, I encountered an issue where the navbar and sidebar do not stay fixed on the screen despite trying various ...

Reorganize child JSON objects into a new object that includes a parent ID

Exploring the realm of JavaScript, I am currently delving into Node.JS to interact with an API and save the data in a SQL Server. Utilizing the "request" and "mssql" Node packages for this task as they possess robust documentation and support. My query re ...

Obtaining the referring URL after being redirected from one webpage to another

I have multiple pages redirecting to dev.php using a PHP header. I am curious about the source of the redirection. <?php header(Location: dev.php); ?> I attempted to use <?php print "You entered using a link on ".$_SERVER["HTTP_REFERER"]; ?> ...

Submitting an AJAX POST request from a partial view within an ASP.NET Core Razor Pages application

My attempt at sending a POST Ajax from a partial view has hit a snag. Here is the code snippet from my partial view: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="../css/s ...

What are some ways to slow down the speed of a canvas animation?

I am currently working on an animation project using JavaScript and canvas. I have a reference fiddle where objects are generated randomly and fall from the top right corner to the bottom left corner, which is fine. However, the issue is that the objects a ...

What is the best way to upload a file to Firebase Storage using React?

I am facing difficulty uploading a file to Firebase in order to retrieve its getDownloadURL. This is the code snippet I currently have: import React, {useState, useEffect} from 'react' import { Container, Button, Row, Col, Form, Alert } from &ap ...

Stop the sudden jump when following a hashed link using jQuery

Below is the code snippet I am working with: $( document ).ready(function() { $( '.prevent-default' ).click(function( event ) { event.preventDefault(); }); }); To prevent the window from jumping when a hashed anchor ...

Tips for maximizing image efficiency using Next.js and Amazon S3

Currently, I'm utilizing nextjs, react-hook-form, and aws to develop a form incorporating images. Here is my existing setup: form.tsx: <Controller name={'photoDump'} control={control} //{...register('photoDump')} render ...

Encountering the error message "Unable to access property 'addEventListener' of null while trying to manipulate innerHTML"

Currently, I am utilizing innerHTML to include certain elements and a wrapper around them. for (i = 0; i < arr.length; i++) { b.innerHTML += "<div class='wrapper'><div class='col-4'>" + arr[i].storeID + "</div> ...

Can you provide guidance on utilizing OneNote JavaScript APIs to interpret indented paragraphs within OneNote?

I keep a notebook that contains the following entries: https://i.stack.imgur.com/MLdO0.png For information on OneNote APIs, you can refer to this link (paragraph class selected already) https://learn.microsoft.com/en-us/javascript/api/onenote/onenote.p ...