40 package okw.gui.adapter.selenium.webdriver;
42 import java.util.ArrayList;
43 import java.util.List;
45 import org.openqa.selenium.By;
46 import org.openqa.selenium.NoSuchFrameException;
47 import org.openqa.selenium.WebDriver;
48 import org.openqa.selenium.WebElement;
49 import org.openqa.selenium.chrome.ChromeDriver;
50 import org.openqa.selenium.firefox.FirefoxDriver;
51 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
53 import okw.exceptions.OKWGUIObjectNotFoundException;
54 import okw.exceptions.OKWGUIObjectNotUniqueException;
55 import okw.log.Logger_Sngltn;
66 private WebDriver driver =
null;
74 public String getCurrentiframeID()
107 public void setDriver( WebDriver fpDriver )
109 this.driver = fpDriver;
112 public WebDriver getDriver( )
118 public void __DriveChrome()
120 this.driver =
new ChromeDriver();
123 public void __DriveFireFox()
125 this.driver =
new FirefoxDriver();
133 public void __DriveUnitDriver()
137 this.driver =
new HtmlUnitDriver(
true );
142 System.out.println( e.getStackTrace() );
167 driver.switchTo().defaultContent();
170 if ( !okw.OKW_Helper.isStringNullOrEmpty( iframeID ) )
174 driver.switchTo().frame( iframeID );
180 catch (NoSuchFrameException e)
182 System.out.println(
"Unable to locate frame with id " + iframeID + e.getStackTrace() );
186 System.out.println(
"Unable to navigate to frame with id " + iframeID + e.getStackTrace() );
217 String return_iFrame =
null;
218 WebElement myWebElement =
null;
222 Exception ExceptionFound =
null;
227 ArrayList<String> iframeIDs =
new ArrayList<String>();
232 MyLogger.
LogPrintDebug(
"Number of iFrames found: " + ((Integer)iframeIDs.size()).toString() );
235 for ( String iframeID : iframeIDs )
239 myWebElement = this.
getElement( iframeID, fpsLocator );
241 if ( myWebElement !=
null )
257 catch ( Exception e )
277 else if ( ExceptionFound !=
null )
281 throw new RuntimeException( ExceptionFound );
287 return return_iFrame;
309 ArrayList<String> lvReturn =
new ArrayList<String>();
314 List<WebElement> iframes = this.driver.findElements(By.tagName(
"iframe"));
318 for (WebElement iframe : iframes)
320 String myID = iframe.getAttribute(
"id");
322 if ( ! okw.OKW_Helper.isStringNullOrEmpty( myID ) )
324 lvReturn.add( myID );
328 myID = iframe.getAttribute(
"name");
330 if ( ! okw.OKW_Helper.isStringNullOrEmpty( myID ) )
332 lvReturn.add( myID );
337 MyLogger.
LogWarning(
"iFrame has neither ID nor Name:" + iframe.toString() );
369 public WebElement
getElement( String fpsFrameID, String fpsLocator )
371 WebElement me =
null;
372 List<WebElement> meme =
null;
376 this.MyLogger.
LogFunctionStartDebug(
"SeDriver.getElement",
"fpsFrameID", fpsFrameID,
"fpsLocator", fpsLocator );
382 meme = this.driver.findElements( By.xpath( fpsLocator ) );
384 if ( meme.size() == 0 )
386 String lvsPrintMe =
"GUI-Objekt nicht gefunden! IFrame: '" + fpsFrameID +
"' Locator: '" + fpsLocator +
"'";
387 this.MyLogger.
LogPrint( lvsPrintMe );
391 else if ( meme.size() > 1 )
393 String lvsPrintMe =
"Locator ist nicht eindeutig! IFrame: '" + fpsFrameID +
"' Locator: '" + fpsLocator +
"'";
401 String lvsPrintMe =
"GUI-Objekt gefunden IFrame: '" + fpsFrameID +
"' Locator: '" + fpsLocator +
"'";
430 public List<WebElement>
getElements( String fpsFrameID, String fpsLocator )
432 List<WebElement> meme =
null;
434 this.MyLogger.
LogFunctionStartDebug(
"SeDriver.getElement",
"fpsFrameID", fpsFrameID,
"fpsLocator", fpsLocator );
442 meme = this.driver.findElements( By.xpath( fpsLocator ) );