Automated Redirects with Selenium Webdriver

Issue Description:

I am currently facing a problem setting up a Selenium webdriver in Java. Every time I attempt to navigate to this specific webpage: Expected Website, I get redirected to the Unintended Website. This redirection occurs regardless of which driver I use (Firefox, Chrome, Edge), and despite trying various solutions, I have been unable to prevent it. It seems that some JavaScript executing during page loading might be causing this unwanted redirection.

Interestingly, when I try to access the same website using a standard browser, I successfully reach the Expected Website as desired.

Objective:

To successfully load the following website using a Selenium webdriver: Expected Website

Additional Details:

The code snippet I have implemented so far:

     System.setProperty("webdriver.gecko.driver", "E:/Downloads/geckodriver.exe");
     File pathToBinary = new File(
     "C:/Program Files (x86)/Mozilla   Firefox/firefox.exe");

     FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
     FirefoxProfile firefoxProfile = new FirefoxProfile();
     driver = new FirefoxDriver(ffBinary,firefoxProfile);

     driver.get("https://www.liketoknow.it/featured");
        try {
             Thread.sleep(10000);
                }catch (InterruptedException e) {}

     driver.quit();

Answer №1

The cause of this occurrence is as follows:

In order to view this page, access must be granted. This can be achieved by logging in on the main website first.

For individuals experiencing a similar issue with redirection:

Try utilizing a different user agent configuration when setting up your Webdriver. Switch between mobile or PC/MAC options based on your specific requirements.

Cheers!

Answer №2

Did you notice that the /featured page is redirecting straight to the main site?

I suggest checking that out first. It seems like there might be a connection issue causing this, and you may end up with the same outcome if you try accessing directly.

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

Can you please provide further clarification on how to use selenium's `find_element_by

from selenium import webdriver from selenium.webdriver.common.keys import Keys browser = webdriver.Chrome("C:/Users/sebastian/desktop/chromedriver.exe") browser.get("http://www.python.org") elem = browser.find_element_by_name("search_bar") elem.clear() ...

DiscordJS | Duplicate embed message in a different conversation

Recently, I set up a synchronization between a form and a Discord webhook. Within the webhook, there are three reactions automatically generated by an external BOT. My goal is to configure it so that when a reaction is selected, a confirmation prompt appea ...

Press the onClick button to return to the previous page or component in a React application

I currently have a div that switches from one component to another by toggling the state when a button is clicked. { !showForm ? ( <div className={styles.showTicketContainer}> <div className={styles.showTicketBox}> ...

Can you please let me know if it's possible to store an ajax function/call for future reuse?

While developing a web app using JavaScript and PHP, I've noticed that I keep rewriting the same ajax calls repeatedly. Is there a way to create a reusable function or variable for these calls, with or without parameters? I'm fairly new to JavaS ...

Is there a way to seamlessly synchronize two databases for optimal efficiency?

I have a vision for a software project that involves keeping multiple databases in sync with a central server database located on a web server. If a user has my software installed on more than one computer, any updates made on one PC should be reflected lo ...

Tips for populating a DOJO Select using JSON data that includes various parameters instead of just label and value

I am trying to populate a DOJO select element with JSON data where the item values for value are expressed by the code property. Here's an example of what I have: //require dojo Select var select = new Select({ name: "stateSelect", ...

Getting started with imports in typescript package

Having trouble with imports in a TypeScript package. I have two classes, A and B, located in the models directory. Currently, I am importing class B into class A like this: import B from "models/B" interface A { b: B } export default A; H ...

The issue of referencing absolute paths on a virtual directory

Whenever there is a virtual directory, my image path references (src='/images/image.jpg') inside my .js files are failing as the virtual directory becomes part of the path hierarchy. In other areas of my application, I am able to manage this iss ...

Response from the server to multiple asynchronous XMLHttpRequests

I'm in the process of creating a Web Application that involves making multiple simultaneous XHR calls using Ajax instead of native Javascript. $.ajax({ type: 'POST', url: 'Services/Service.asmx/MyFunction', contentTyp ...

dismiss facial recognition event

Does anyone know how to implement a cancel button in Facebox when using it to delete data from MySQL? I want the window to unload when the user clicks on cancel. This is the code snippet I am currently using with Facebox: Are You Sure You Want To Delete ...

Python-Selenium crawler experiencing freezing issues, particularly in headless mode with a non-reproducible bug

After developing a web crawler that extracts data for a user-provided list of products, I encountered an issue where the crawler occasionally freezes. This problem seems to occur more frequently when running in headless mode and with longer product lists. ...

The fullscreen API allows for the creation of a full-screen element containing internal elements, while also enabling the functionality

Is it possible to utilize the fullscreen API to make any element fullscreen, even if it contains multiple internal elements, while still maintaining the functionality of dropdowns and other custom elements that may be located in different areas of the page ...

Leveraging JavaScript to store XHR documents

My goal is to save a JSON file that is retrieved on a page after logging in with a POST request. Since there is no available API, I am looking to download the response of a script called during the page load as a JSON file using Greasemonkey. The page I&a ...

Using location.reload with the argument of true is no longer recommended

While it's generally not recommended to reload an Angular Single Page Application, there are situations where a full reload is necessary. I've been informed by TSLint that reloading is deprecated. Is there any other solution available for this ...

What is the best way to test the stopPropagation functionality of a click event using React Testing Library?

In my current project, I have a custom Icon component that has an onClick() prop. This prop is triggered when the icon is clicked, and it also includes a function called event.stopPropagation() which stops the event from bubbling up the DOM tree. I need t ...

Guide to picking an item from a drop-down menu using Selenium WebDriver in conjunction with Java

I am struggling to choose a category from the HTML code below. I have tried various methods and suggestions from blogs, but so far, I haven't been successful in selecting the options. Any guidance on this matter would be greatly appreciated. One appr ...

Selenium is struggling to locate a specific element within the webpage

I'm having some trouble using Selenium to locate and click on a specific element. The element I need to interact with looks like this: <button class="btn btn-link">search criteria: on support work 'took place on' (grouped by ...

What strategies can be implemented to prevent the custom hook and Student component from re-rendering unnecessarily?

In the code snippet below, both the useStudentState custom hook and the Student component are being rendered even when only the first <Student {...studentStateA} /> component is changed. For example, if you input a new value in the first box and pre ...

Updating a Vue ref does not result in the component reflecting the changes made

My Vue3 form has three text inputs and a group of checkboxes. To implement this, I am using the bootstrap-vue form along with its checkbox-group component. After calling an API to fetch default values for the form, I update the ref as shown below. Interes ...

Why is my React Native button's onPress event not functioning correctly?

I am encountering an issue with the onPress event handler. I have tried multiple solutions but none seem to work with the handleClick function. Here are the different approaches I attempted: onPress={this.handleClick} onPress={this.handleClick()} onPress= ...