List of usage examples for org.openqa.selenium WebDriver switchTo
TargetLocator switchTo();
From source file:org.kuali.khr.hub.util.Helper.java
License:Educational Community License
public static void switchToDefaultFrame(WebDriver driver) { driver.switchTo().defaultContent(); }
From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java
License:Educational Community License
/** * Asserts that the Expanded Text Area is providing a popup window in which to change its value. Verifies that the that this is working properly by * performing the following:// w w w . j a v a 2 s . co m * <ol> * <li>The text area is set to the {@code originalText} value</li> * <li>The pencil button is clicked on, opening in a popup window</li> * <li>The text in the popup window is examined to verify that it is equal to {@code originalText}</li> * <li>The popup window text area is changed to {@code expandedAreaText}</li> * <li>The "Continue" button is clicked on, closing the popup window</li> * <li>The resulting web page is examined to verify that the text area has changed to the value of {@code expandedAreaText}</li> * </ol> * * @param textAreaId identifies the text area * @param originalText the string to set the original text area to * @param expandedAreaText the string to set in the popup window text area */ public final void assertExpandedTextArea(final String textAreaId, final String originalText, final String expandedAreaText) { set(textAreaId, originalText); String parentWindowHandle = driver.getWindowHandle(); final String textAreaButtonLocator = "//input[starts-with(@name,'methodToCall.updateTextArea') and contains(@name, '" + textAreaId + "')]"; WebElement textAreaButton = new ElementExistsWaiter("Expand button for " + textAreaId + " not found") .until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return getElementByXPath(textAreaButtonLocator); } }); textAreaButton.click(); switchToPopupWindow(parentWindowHandle); assertEquals(originalText, get(textAreaId)); set(textAreaId, expandedAreaText); final String continueButtonLocator = "methodToCall.postTextAreaToParent"; WebElement continueButton = new ElementExistsWaiter("Continue button for " + textAreaId + " not found") .until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { WebElement element = null; List<WebElement> elements = getActiveElementsByName(continueButtonLocator, false); if (!elements.isEmpty()) { element = elements.get(0); } return element; } }); continueButton.click(); driver.switchTo().window(parentWindowHandle); assertEquals(expandedAreaText, get(textAreaId)); }
From source file:org.kuali.rice.krad.labs.transactional.LabsLookupTravelAuthorizationDocumentCloseActionAft.java
License:Educational Community License
public void testTravelAuthorizationDocumentLookupAndClose() throws Exception { final String xpathExpression = "//iframe[1]"; driver.switchTo().frame(driver.findElement(By.xpath(xpathExpression))); // search based on document type waitAndTypeLabeledInput("Document Type:", "TravelAuthorization"); // click the search button jGrowl("Click the Search button"); final String imgXpath = "//input[contains(@src,'/kr/static/images/buttonsmall_search.gif')]"; waitAndClick(By.xpath(imgXpath));/*from ww w. jav a 2 s . c o m*/ // click on the first item returned. jGrowl("Click on the first result in status SAVED returned from the search."); String windowHandle = driver.getWindowHandle(); waitAndClick(By.xpath("//td[contains(text(),'SAVED')]/../td[1]/a")); // wait for the new window to pop up new WebDriverWait(driver, 10).until(new ExpectedCondition<Object>() { @Override public Object apply(WebDriver driver) { //Wait until we have at least two windows. return driver.getWindowHandles().size() > 1; } }); // switch focus to the new handle for (String handle : driver.getWindowHandles()) { if (!handle.equals(windowHandle)) { driver.switchTo().window(handle); break; } } // click the close button waitAndClickButtonByText("Close", WebDriverUtils.configuredImplicityWait() * 10); waitAndClickCancelSaveOnClose(); waitForTextPresent("Development made easy"); }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>//from w w w . j av a 2s. c o m * Accept the javascript alert (clicking OK). * </p> * * @param driver WebDriver to accept alert on */ public static void alertAccept(WebDriver driver) { Alert alert = driver.switchTo().alert(); jGrowl(driver, "AFT Step", false, "AFT Step: Accept Alert " + WebDriverUtils.alertText(driver)); alert.accept(); }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>//w ww . ja v a 2 s .co m * Dismiss the javascript alert (clicking Cancel). * </p> * * @param driver WebDriver to dismiss alert on */ public static void alertDismiss(WebDriver driver) { Alert alert = driver.switchTo().alert(); jGrowl(driver, "AFT Step", false, "AFT Step: Dismiss Alert " + WebDriverUtils.alertText(driver)); alert.dismiss(); }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>// w w w .ja va 2 s. c om * Return alert text. * </p> * * @param driver to get alert text from * @return alert text */ public static String alertText(WebDriver driver) { return driver.switchTo().alert().getText(); }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>/*from w w w. ja v a 2s. c o m*/ * Return true if an alert is present, false if not. * </p> * * @param driver to check for presents of alert on * @return true if there is an alert present, false if not */ public static boolean isAlertPresent(WebDriver driver) { try { driver.switchTo().alert(); return true; } catch (Exception e) { return false; } }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>//from www. ja va2 s . c o m * Select frame defined by locator without throwing an Exception if it doesn't exist. * </p> * * @param driver to select frame on * @param locator to identify frame to select */ public static void selectFrameSafe(WebDriver driver, String locator) { try { driver.switchTo().frame(locator); } catch (NoSuchFrameException nsfe) { // don't fail } }
From source file:org.kurento.tutorial.one2onecall.test.One2OneCallIT.java
License:Open Source License
private void waitForIncomingCallDialog(WebDriver driver) throws InterruptedException { int i = 0;// www . j a v a2s . c o m for (; i < TEST_TIMEOUT; i++) { try { driver.switchTo().alert(); break; } catch (NoAlertPresentException e) { Thread.sleep(1000); } } if (i == TEST_TIMEOUT) { throw new RuntimeException("Timeout (" + TEST_TIMEOUT + " seconds) waiting for incoming call"); } }
From source file:org.mozilla.zest.core.v1.ZestClientSwitchToFrame.java
License:Mozilla Public License
@Override public String invoke(ZestRuntime runtime) throws ZestClientFailException { WebDriver wd = runtime.getWebDriver(this.getWindowHandle()); if (wd == null) { throw new ZestClientFailException(this, "No client: " + runtime.getVariable(getWindowHandle())); }//from w w w . j a v a2s . c om if (this.frameIndex >= 0) { wd.switchTo().frame(this.frameIndex); } else if (this.isParent()) { wd.switchTo().parentFrame(); } else { wd.switchTo().frame(this.frameName); } return this.windowHandle; }