Advertisement
Gamebuster

Untitled

Dec 30th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. #Gwebdriver.class
  2.  
  3. public WebElement GetElement(SearchType searchType, String parameter){
  4.         WebElement element;
  5.         try{
  6.             if (searchType == SearchType.CLASS_NAME){
  7.                 element = driver.findElement(By.className(parameter));
  8.                 return element;
  9.             }
  10.             else if (searchType == SearchType.CSS_SELECTOR){
  11.                 element = driver.findElement(By.cssSelector(parameter));
  12.                 return element;
  13.             }
  14.             else if (searchType == SearchType.ID){
  15.                 element = driver.findElement(By.id(parameter));
  16.                 return element;
  17.             }
  18.             else if (searchType == SearchType.LINK_TEXT){
  19.                 element = driver.findElement(By.linkText(parameter));
  20.                 return element;
  21.             }
  22.             else if (searchType == SearchType.NAME){
  23.                 System.out.println("Driver is: " + driver);
  24.                 System.out.println("Type is: " + type);
  25.                 System.out.println("Name is: " + name);
  26.                 System.out.println("Searching by: " + searchType);
  27.                 element = driver.findElement(By.name(parameter));
  28.                 if (element instanceof WebElement){
  29.                     System.out.println(element + " is a Web element");
  30.                 }
  31.                 System.out.println(element);
  32.                 System.out.println(element.getClass());
  33.                 return element;
  34.             }
  35.             else if (searchType == SearchType.PARTIAL_LINK_TEXT){
  36.                 element = driver.findElement(By.partialLinkText(parameter));
  37.                 return element;
  38.             }
  39.             else if (searchType == SearchType.TAG_NAME){
  40.                 element = driver.findElement(By.tagName(parameter));
  41.                 return element;
  42.             }
  43.             else if (searchType == SearchType.XPATH){
  44.                 element = driver.findElement(By.xpath(parameter));
  45.                 return element;
  46.             }
  47.         }
  48.         catch (NoSuchElementException e){
  49.             if (GameBuSK.debug == true){
  50.                 e.printStackTrace();
  51.             }
  52.             System.out.println("No element was found using " + type + " with parameter \"" + parameter + "\" in " + driver.getTitle());
  53.         }
  54.         finally{
  55.             return null;
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement