How to follow redirect in WebDriver

100 Views Asked by At

I'm very new to WebDriver, and the whole concept of a headless browser is hard to wrap my head around, and I could use some help...

This might be a stupid Idea for a project in the first place, but I thought I'd give it a shot, so please bear with me.

So I'm using cappex.com as my starting website, and then from there my program will search for GiveAway scholarships. And I have a big ol' set of variables that it will search for then attempt to imput. I'm having a lot of fun with this, the only problem I'm having is when ever it clicks a new scholarship it redirects in a new tab. see linked video for ex.

Is there a way to follow that redirect, like so I can now interact with that website.

there is no method of selenium web diver that I can see for redirects, so I'm not sure how to proceed.

I would share my code, but there's basically nothing yet, and given the nature of the project there is a lot of personal information. I'm programming using Java, in eclipse.

Thank you for your time, and help.

1

There are 1 best solutions below

0
Viki On BEST ANSWER

I had the same problem in past so what I did. Get the WindowHandles

ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());     

Switch to new opened tab

driver.switchTo().window(tabs.get(1));

then do whatever you want.

And if you want to switch to previous tab then

driver.switchTo().window(tabs.get(0));

You can switch to other tabs as well based on the their index.