javaseleniumhttp-redirectchrome-options

How do I avoid Selenium redirect using Java?


I am trying to go to reddit.com, perform an action, then go to old.reddit.com and compare results. I'm not able to go to old.reddit.com because it redirects to reddit.com. How do I prevent this?

Here is my code

ChromeOptions ops = new ChromeOptions();
ops.addArguments("--disable-notifications", "start-maximized", "--disable-popup-blocking");

WebDriver driver = new ChromeDriver(ops);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(7));
driver.get("https://www.reddit.com");
WebElement e =driver.findElement(By.name("q"));
e.sendKeys("New York");
Thread.sleep(2000);
e.sendKeys(Keys.RETURN);
Thread.sleep(2000);
driver.navigate().to("http://www.old.reddit.com/");

I've tried not using ChromeOptions and clicking accept when I get the security warning. I've tried incognito any other workaround i can think of but I keep getting stuck.


Solution