Advertisement
SeleniumETrainR

Example > Free Bulk URL Shortener > Using selenium Webdriver

Dec 21st, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. import java.util.concurrent.TimeUnit;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.firefox.FirefoxDriver;
  6.  
  7.  
  8. public class FreeBulkURLShortener {
  9.     public static Xls_Reader XLStinyurl = null;
  10.     public static String LongURL = null;
  11.     public static String ShortURL = null;
  12.    
  13.     public static String WebsiteURL = null;
  14.     public static String URLTextBox = null;
  15.     public static String ButtonShortenURL = null;
  16.     public static String short_url = null;
  17.    
  18.     public static void main(String[] args) {
  19.          
  20.         WebDriver myTestDriver = new FirefoxDriver();
  21.         myTestDriver.manage().window().maximize();
  22.        
  23.         myTestDriver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
  24.        
  25.          
  26.         //  tinyurl
  27.         WebsiteURL = "https://tinyurl.com/";
  28.         URLTextBox = "html/body/table[2]/tbody/tr[2]/td/form/table/tbody/tr/td/input[2]";
  29.         ButtonShortenURL = "html/body/table[2]/tbody/tr[2]/td/form/table/tbody/tr/td/input[3]";
  30.         short_url ="html/body/table[2]/tbody/tr[2]/td/blockquote[2]/b";
  31.        
  32. //      //http://is.gd/
  33. //      WebsiteURL = "http://is.gd/";
  34. //      URLTextBox = "//*[@id='urlboxcontainer']/input";
  35. //      ButtonShortenURL = "//*[@id='mainform']/input";
  36. //      short_url ="//*[@id='short_url']";
  37.  
  38.        
  39. //      //http://www.snipurl.com/
  40. //      WebsiteURL = "http://www.snipurl.com/";
  41. //      URLTextBox = "//*[@id='urltext']";
  42. //      ButtonShortenURL = "//*[@id='content']/input";
  43. //      short_url ="//*[@id='hrowmsg']/input";
  44.  
  45.         myTestDriver.get(WebsiteURL);
  46.        
  47.         //*************************************************************
  48.         XLStinyurl = new Xls_Reader(System.getProperty("user.dir")+"\\LinksDB.xlsx");
  49.         System.out.println("Total no of rows in excel sheet - "+ XLStinyurl.getRowCount("Sheet1"));
  50.    
  51.        
  52.        
  53.         //*************************************************************    
  54.        
  55.         for(int i=0;i<=XLStinyurl.getRowCount("Sheet1");i++){
  56.             //Enter URL
  57.             myTestDriver.findElement(By.xpath(URLTextBox)).sendKeys(XLStinyurl.getCellData("Sheet1", "LongURL", i+2));
  58.            
  59.             System.out.println(XLStinyurl.getCellData("Sheet1", "LongURL", i+2));
  60.            
  61.             //Click on submit
  62.             myTestDriver.findElement(By.xpath(ButtonShortenURL)).click();
  63.            
  64.             //Get result
  65.             XLStinyurl.setCellData("Sheet1", "ShortURL", i+2, myTestDriver.findElement(By.xpath(short_url)).getText());
  66.             System.out.println(myTestDriver.findElement(By.xpath(short_url)).getText());
  67.            
  68.            
  69.             myTestDriver.get(WebsiteURL);
  70.            
  71.         }
  72.        
  73.          
  74.         myTestDriver.quit();
  75.        
  76.        
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement