Open URLs from File

46 views
Skip to first unread message

Sean

unread,
Sep 10, 2015, 11:41:38 AM9/10/15
to Selenium Users
Hi.
    I'm new to selenium webdriver and am attempting to create a simple test to verify a list of URLs which are stored in a .csv file. I have a csv file which contains a list of different URLs.  I would like to have a test which opens up each url from Column 1 and compares the loaded pages url to colum 2.  Most of the urls are redirects.  For example: open Cell A1 which equals www.exmaple.com then verify page redirects to what is listed in B1 which is www.test.com.
Does anyone know the code to do something like this? Or could point me in the right direction.  The url list is currently in a csv file but it could be converted to something different. the list is large are is always being updated.


Thanks

Travis

unread,
Sep 10, 2015, 4:07:16 PM9/10/15
to Selenium Users
Assuming you have opened the csv file and are going through it one line at a time, you could use the getCurrentUrl method.  So, something like this (in Java):

WebDriver driver = new FirefoxDriver();
driver.get(url1); //Open the URL from column 1
String endUrl = driver.getCurrentUrl();

Then just compare endUrl with whatever is stored in the second column.  If they are the same, the test has passed.  If they're different, it hasn't.

Hope that helps.
Reply all
Reply to author
Forward
0 new messages