How do I avoid Selenium redirect using Java?

489 views Asked by At

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.

2

There are 2 answers

0
Himanshu Raj On BEST ANSWER
  • Correct URL ie https://old.reddit.com/. your are missing 's' in http and adding extra 'www' in URL

  • This driver.navigate().to("https://old.reddit.com/"); works fine in my ide;

1
Penguin On

Your link for old reddit is missing the "s" on http. https://old.reddit.com/