Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Gwebdriver.class
- public WebElement GetElement(SearchType searchType, String parameter){
- WebElement element;
- try{
- if (searchType == SearchType.CLASS_NAME){
- element = driver.findElement(By.className(parameter));
- return element;
- }
- else if (searchType == SearchType.CSS_SELECTOR){
- element = driver.findElement(By.cssSelector(parameter));
- return element;
- }
- else if (searchType == SearchType.ID){
- element = driver.findElement(By.id(parameter));
- return element;
- }
- else if (searchType == SearchType.LINK_TEXT){
- element = driver.findElement(By.linkText(parameter));
- return element;
- }
- else if (searchType == SearchType.NAME){
- System.out.println("Driver is: " + driver);
- System.out.println("Type is: " + type);
- System.out.println("Name is: " + name);
- System.out.println("Searching by: " + searchType);
- element = driver.findElement(By.name(parameter));
- if (element instanceof WebElement){
- System.out.println(element + " is a Web element");
- }
- System.out.println(element);
- System.out.println(element.getClass());
- return element;
- }
- else if (searchType == SearchType.PARTIAL_LINK_TEXT){
- element = driver.findElement(By.partialLinkText(parameter));
- return element;
- }
- else if (searchType == SearchType.TAG_NAME){
- element = driver.findElement(By.tagName(parameter));
- return element;
- }
- else if (searchType == SearchType.XPATH){
- element = driver.findElement(By.xpath(parameter));
- return element;
- }
- }
- catch (NoSuchElementException e){
- if (GameBuSK.debug == true){
- e.printStackTrace();
- }
- System.out.println("No element was found using " + type + " with parameter \"" + parameter + "\" in " + driver.getTitle());
- }
- finally{
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement