Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.TimeUnit;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- public class FreeBulkURLShortener {
- public static Xls_Reader XLStinyurl = null;
- public static String LongURL = null;
- public static String ShortURL = null;
- public static String WebsiteURL = null;
- public static String URLTextBox = null;
- public static String ButtonShortenURL = null;
- public static String short_url = null;
- public static void main(String[] args) {
- WebDriver myTestDriver = new FirefoxDriver();
- myTestDriver.manage().window().maximize();
- myTestDriver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
- // tinyurl
- WebsiteURL = "https://tinyurl.com/";
- URLTextBox = "html/body/table[2]/tbody/tr[2]/td/form/table/tbody/tr/td/input[2]";
- ButtonShortenURL = "html/body/table[2]/tbody/tr[2]/td/form/table/tbody/tr/td/input[3]";
- short_url ="html/body/table[2]/tbody/tr[2]/td/blockquote[2]/b";
- // //http://is.gd/
- // WebsiteURL = "http://is.gd/";
- // URLTextBox = "//*[@id='urlboxcontainer']/input";
- // ButtonShortenURL = "//*[@id='mainform']/input";
- // short_url ="//*[@id='short_url']";
- // //http://www.snipurl.com/
- // WebsiteURL = "http://www.snipurl.com/";
- // URLTextBox = "//*[@id='urltext']";
- // ButtonShortenURL = "//*[@id='content']/input";
- // short_url ="//*[@id='hrowmsg']/input";
- myTestDriver.get(WebsiteURL);
- //*************************************************************
- XLStinyurl = new Xls_Reader(System.getProperty("user.dir")+"\\LinksDB.xlsx");
- System.out.println("Total no of rows in excel sheet - "+ XLStinyurl.getRowCount("Sheet1"));
- //*************************************************************
- for(int i=0;i<=XLStinyurl.getRowCount("Sheet1");i++){
- //Enter URL
- myTestDriver.findElement(By.xpath(URLTextBox)).sendKeys(XLStinyurl.getCellData("Sheet1", "LongURL", i+2));
- System.out.println(XLStinyurl.getCellData("Sheet1", "LongURL", i+2));
- //Click on submit
- myTestDriver.findElement(By.xpath(ButtonShortenURL)).click();
- //Get result
- XLStinyurl.setCellData("Sheet1", "ShortURL", i+2, myTestDriver.findElement(By.xpath(short_url)).getText());
- System.out.println(myTestDriver.findElement(By.xpath(short_url)).getText());
- myTestDriver.get(WebsiteURL);
- }
- myTestDriver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement