Selenium: Issue with pageLoadTimeout not being effective on websites with continuous redirects

I utilize Selenium to navigate through various websites and save their HTML markup.

To increase efficiency, I've implemented a pageLoadTimeout to trigger an exception for sites that take too long to load:

driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

However, this method doesn't seem effective for websites that are constantly redirecting. For instance, consider this site: .

Is there a way to set a timeout for such websites? My main focus is on navigating back from the driver.get(url) statement rather than loading the content.

Answer №1

It is recommended to wait for the JavaScript to return a complete status before proceeding.

private WebDriverWait wait;

try
{
   wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));                
   wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
}
catch(Exception ex)
{}

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

Executing the Python Selenium script to interact with an element inside a frame

Encountering a problem on LinkedIn where clicking the "Connect" button brings up a frame like this: https://i.stack.imgur.com/tP1pH.png I am attempting to click the "Send now" button but it is not visible. I have tried switching frames using various id/c ...

Using Selenium and Python to scrape text from a continuously refreshing webpage after each scroll

Currently, I am utilizing Selenium/python to automatically scroll down a social media platform and extract posts. At the moment, I am gathering all the text in one go after scrolling a set number of times (see code below), but my objective is to only gathe ...

Using Python Selenium web-driver to hide console windows within a tkinter application

After creating a basic GUI using the tkinter library, I implemented a feature that opens a new thread with Selenium when the user clicks on a button: In the start_button3_callback method: # Initiating a new thread to run the button3_callback function in t ...

Does Serenity BDD have a designated feature for managing alerts?

Trying to manage alerts or other types of popups on a browser? Dealing with an alert popup and wondering if there is a specific function in Serenity BDD to handle it, like driver.switchto().alert();? Even though Serenity BDD is great for handling element ...

Every time I try to run my scripts on PyCharm using Jenkins, I keep receiving a notification to

While attempting to execute automated tests on the cloud version of Jenkins, I encountered the following error: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-0739wibs/cryptograph ...

Initially encountering an error when launching the Protractor tool, however, it functions smoothly thereafter

Running "protractor_webdriver:start" (protractor_webdriver) task Initiating Protractor Webdriver Starting Selenium server: http://127.0.0.1:4444 Running "protractor:start" (protractor) task webdriver-manager path: E:\Work\Test&bs ...

What is the process for extracting data from MS 97-2003 Worksheet using Selenium Webdriver?

I am attempting to access and read the .xls file (MS 97-20003 Worksheet) that has been downloaded from our application using Selenium WebDriver. However, I am encountering the following error: "org.apache.poi.poifs.filesystem.NotOLE2FileException: The sup ...

During the second test, Selenium was unable to locate the element

Encountering the same issue with every test script I attempt to create using selenium + TestNG. After the first @test method, webdriver fails to identify elements in the following @test methods. Illustratively, consider the scenario: The web driver loads ...

What is the correct way to use quotation marks and apostrophes in writing?

I'm looking to create a JavaScript popup with the message xxx'yyy"zzz using Selenium webdriver. I've tried the following code without success: JavascriptExecutor javascript = (JavascriptExecutor) driver; String javaScript_str = "alert(&apos ...

Chromedriver 80 causing StaleElementReferenceException with Selenium

After the Chromedriver 80 update, the following code that used to work is now causing a StaleElementReferenceException when the element is present in the DOM: public static void WaitUntilElementNotExists(string clase) { Instance.Manage().Timeouts(). ...

I am unable to generate png maps using folium with the combination of selenium and firefox

I have been attempting to export a map that I created using folium in Python to a png file. I came across a post suggesting that this can be achieved by using selenium with the following code snippet: Export a folium map as a png import io from PIL import ...

C# Extent Reports are not generating the HTML report file while running a test

I am exploring how to implement ExtentReports in Visual Studio C#. After running a test case, the html report file is not being created. I have checked my code but cannot identify the issue. I believe the path to my reports folder is accurate. I have set ...

Organizing webpage data into a dictionary stored in a table

I am currently working on extracting tables from a webpage in order to store the headers as keys and the body as values, while also denoting which page they belong to. Here's my attempted code snippet: from selenium import webdriver from selenium.webd ...

Attempting to retrieve an image from Tumblr using Java and the Selenium automation tool

I'm facing an issue while attempting to download images from Tumblr using Java Selenium. After extracting the image URL from the source and downloading the images, I noticed that they are in unsupported formats and are smaller than expected. Can someo ...

Using iedriverserver.exe to manage Edge in IE Mode with VBA scripting

Are there any code examples available for controlling Edge in IE Mode using iedriverserver.exe in VBA? I have the exe downloaded but am having trouble adding the necessary library to tools->reference in my VBA project. If anyone has experience with this t ...

a unique subroutine specifically designed for handling time-sensitive events triggers an exception

I'm conducting a test on an angular web-app using Selenium and Python. To set up data for the test, I'm making API calls and need to wait for the data to appear in the front-end before proceeding with the test. Currently, we have a 60-second wait ...

iterate over elements with dynamic values in selenium

I am currently facing a challenge where I extract text from a website and then need to use it in a loop to continuously click on elements based on that variable. The code I have written only loops for 5 times, but the desired behavior is to click on elemen ...

Issue with starting the driver server for Selenium Edge Chromium in Java has caused a WebDriverException due to timeout

I encountered an error while attempting to run selenium using Java in the Edge Chromium browser org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: '4.0.0-alpha-5', revision: 'b3a0d621c ...

Steps to clear the existing input from a text field and input new data using Selenium WebDriver

I encountered an issue while using a Selenium script to read values from an Excel sheet and pass them to a text field. Initially, I input invalid values with sendkeys(), then correct values in a second attempt, but they are being appended to the previous v ...

What is the best way to continuously run tests in Python with Selenium and unittest?

In this test snippet, you can see my test class. It runs successfully when called once with the command python3 main.py. However, there seems to be an issue when attempting to run this test multiple times, say 100 times. How can I achieve that? When trying ...