List of usage examples for org.openqa.selenium WebDriver getWindowHandle
String getWindowHandle();
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method shall close current window and select previous window to carry on testing * // www. j a v a 2 s . c o m * @param driver * @param parentWindow */ public void SelectParentWindow(final WebDriver driver, final String parentWindow) { // Need guarantee we close everything WebDriver previewWindow = null; String currentWindowHandle = driver.getWindowHandle(); previewWindow = driver.switchTo().window(currentWindowHandle); previewWindow.close(); driver.switchTo().window(parentWindow); }
From source file:com.redhat.darcy.webdriver.WebDriverBrowserFactory.java
License:Open Source License
/** * Boiler plate code to take a freshly minted driver, an {@link ElementConstructorMap}, and * construct a {@link WebDriverParentContext} which is used to create a browser assigned to the * current driver's target window.//from w ww. j a va 2 s .c o m */ protected static Browser makeBrowser(WebDriver driver, ElementConstructorMap elementMap) { String currentWindowHandle = driver.getWindowHandle(); WebDriverTarget target = WebDriverTargets.window(currentWindowHandle); CachingTargetLocator cachingLocator = new CachingTargetLocator(target, driver); WebDriverParentContext context = new TargetedWebDriverParentContext(target, cachingLocator, driver::getWindowHandles, elementMap); return context.findById(Browser.class, currentWindowHandle); }
From source file:com.smartqa.utils.WebDriverUtils.java
License:Apache License
/** * close web drvier properly//from w w w . j ava 2 s .com * * @param driver */ public static void closeWebDriver(WebDriver driver) { if (driver == null) return; try { String current = driver.getWindowHandle(); Set<String> otherWins = driver.getWindowHandles(); for (String winId : otherWins) if (winId.equals(current)) continue; else driver.switchTo().window(winId).close(); } catch (Exception ex) { LOG.warn("Error happen when close web driver: " + ex.getMessage()); } finally { try { driver.quit(); } catch (Exception ex) { } } }
From source file:com.springer.omelet.driver.DriverUtility.java
License:Apache License
/*** * Switching between windows.//from w w w .j a va 2 s .c o m * * @param driver * @param sString * :Target window Title * @return:True if window switched */ public static boolean switchToWindow(WebDriver driver, String sString) { String currentHandle = driver.getWindowHandle(); Set<String> handles = driver.getWindowHandles(); if (handles.size() >= 1) { for (String handle : handles) { LOGGER.debug("Switching to other window"); driver.switchTo().window(handle); if (driver.getTitle().contains(sString)) { LOGGER.info("switched to window with title:" + sString); return true; } } driver.switchTo().window(currentHandle); LOGGER.info("Window with title:" + sString + " Not present,Not able to switch"); return false; } else { LOGGER.info("There is only one window handle :" + currentHandle); return false; } }
From source file:com.thoughtworks.selenium.webdriven.commands.GetAllWindowNames.java
License:Apache License
@Override protected String[] handleSeleneseCommand(WebDriver driver, String ignored, String alsoIgnored) { String current = driver.getWindowHandle(); List<String> attributes = new ArrayList<>(); for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); attributes.add(((JavascriptExecutor) driver).executeScript("return window.name").toString()); }/*from w w w . j a v a 2 s . c om*/ driver.switchTo().window(current); return attributes.toArray(new String[attributes.size()]); }
From source file:com.thoughtworks.selenium.webdriven.commands.GetAllWindowTitles.java
License:Apache License
@Override protected String[] handleSeleneseCommand(WebDriver driver, String ignored, String alsoIgnored) { String current = driver.getWindowHandle(); List<String> attributes = new ArrayList<>(); for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); attributes.add(driver.getTitle()); }//from w w w.ja v a 2s .co m driver.switchTo().window(current); return attributes.toArray(new String[attributes.size()]); }
From source file:com.thoughtworks.selenium.webdriven.commands.GetAttributeFromAllWindows.java
License:Apache License
@Override protected String[] handleSeleneseCommand(WebDriver driver, String attributeName, String ignored) { String current = driver.getWindowHandle(); List<String> attributes = new ArrayList<>(); for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); String value = (String) ((JavascriptExecutor) driver).executeScript("return '' + window[arguments[0]];", attributeName);//from w w w. j a v a2 s .co m attributes.add(value); } driver.switchTo().window(current); return attributes.toArray(new String[attributes.size()]); }
From source file:com.thoughtworks.selenium.webdriven.commands.WaitForPopup.java
License:Apache License
@Override protected Void handleSeleneseCommand(final WebDriver driver, final String windowID, final String timeout) { final long millis = toLong(timeout); final String current = driver.getWindowHandle(); new Wait() {/* w ww.ja va 2 s. c o m*/ @Override public boolean until() { try { windows.selectPopUp(driver, windowID); return !"about:blank".equals(driver.getCurrentUrl()); } catch (SeleniumException e) { // Swallow } return false; } }.wait(String.format("Timed out waiting for %s. Waited %s", windowID, timeout), millis); driver.switchTo().window(current); return null; }
From source file:com.thoughtworks.selenium.webdriven.commands.Windows.java
License:Apache License
public Windows(WebDriver driver) { originalWindowHandle = driver.getWindowHandle(); }
From source file:com.thoughtworks.selenium.webdriven.commands.Windows.java
License:Apache License
public void selectWindow(WebDriver driver, String windowID) { if (null == windowID || "null".equals(windowID) || "".equals(windowID)) { driver.switchTo().window(originalWindowHandle); } else if ("_blank".equals(windowID)) { selectBlankWindow(driver);/*from www . j a v a 2s . c om*/ } else { if (windowID.startsWith("title=")) { selectWindowWithTitle(driver, windowID.substring("title=".length())); return; } if (windowID.startsWith("name=")) { windowID = windowID.substring("name=".length()); } try { driver.switchTo().window(windowID); } catch (NoSuchWindowException e) { selectWindowWithTitle(driver, windowID); } } if (lastFrame.containsKey(driver.getWindowHandle())) { // If the frame has gone, fall back try { selectFrame(driver, lastFrame.get(driver.getWindowHandle())); } catch (SeleniumException e) { lastFrame.remove(driver.getWindowHandle()); } } }