Codota Logo
WebDriver.switchTo
Code IndexAdd Codota to your IDE (free)

How to use
switchTo
method
in
org.openqa.selenium.WebDriver

Best Java code snippets using org.openqa.selenium.WebDriver.switchTo (Showing top 20 results out of 1,026)

  • Common ways to obtain WebDriver
private void myMethod () {
WebDriver w =
  • Codota Iconnew FirefoxDriver()
  • Codota Iconnew ChromeDriver()
  • Codota IconCapabilities capabilities;new ChromeDriver(capabilities)
  • Smart code suggestions by Codota
}
origin: selenide/selenide

public SelenideTargetLocator(Config config, WebDriver webDriver) {
 this.config = config;
 this.webDriver = webDriver;
 this.delegate = webDriver.switchTo();
}
origin: stackoverflow.com

 WebDriver driver = ... // initialize the driver
WebElement currentElement = driver.switchTo().activeElement();
origin: selenide/selenide

@Override
public WebDriver apply(WebDriver driver) {
 try {
  return driver.switchTo().frame(driver.findElement(locator));
 } catch (NoSuchFrameException e) {
  return null;
 } catch (WebDriverException e) {
  return null;
 }
}
origin: galenframework/galen

@Override
public void switchToParentFrame() {
  driver.switchTo().parentFrame();
}
origin: selenide/selenide

@Override
public WebDriver apply(WebDriver driver) {
 try {
  List<String> windowHandles = new ArrayList<>(driver.getWindowHandles());
  return driver.switchTo().window(windowHandles.get(index));
 } catch (IndexOutOfBoundsException windowWithIndexNotFound) {
  return null;
 }
}
origin: galenframework/galen

@Override
public void switchToFrame(PageElement mainObject) {
  WebPageElement webPageElement = (WebPageElement)mainObject;
  driver.switchTo().frame(webPageElement.getWebElement());
}
origin: selenide/selenide

@Override
public WebDriver apply(WebDriver driver) {
 try {
  return driver.switchTo().window(nameOrHandleOrTitle);
 } catch (NoSuchWindowException windowWithNameOrHandleNotFound) {
  try {
   return windowByTitle(driver, nameOrHandleOrTitle);
  } catch (NoSuchWindowException e) {
   return null;
  }
 }
}
origin: selenide/selenide

private void closeNewWindows(WebDriver webDriver, String currentWindowHandle, Set<String> currentWindows) {
 Set<String> windowHandles = webDriver.getWindowHandles();
 if (windowHandles.size() != currentWindows.size()) {
  Set<String> newWindows = new HashSet<>(windowHandles);
  newWindows.removeAll(currentWindows);
  log.info("File has been opened in a new window, let's close " + newWindows.size() + " new windows");
  for (String newWindow : newWindows) {
   log.info("  Let's close " + newWindow);
   try {
    webDriver.switchTo().window(newWindow);
    webDriver.close();
   }
   catch (NoSuchWindowException windowHasBeenClosedMeanwhile) {
    log.info("  Failed to close " + newWindow + ": " + Cleanup.of.webdriverExceptionMessage(windowHasBeenClosedMeanwhile));
   }
   catch (Exception e) {
    log.warning("  Failed to close " + newWindow + ": " + e);
   }
  }
  webDriver.switchTo().window(currentWindowHandle);
 }
}
origin: stackoverflow.com

Alert javascriptAlert = myTestDriver.switchTo().alert();
Alert javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt.sendKeys("This is Selenium Training");
javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt = myTestDriver.switchTo().alert();
myTestDriver.findElement(By.xpath("//input[@value = 'confirm']")).click();
Alert javascriptconfirm = myTestDriver.switchTo().alert();
javascriptconfirm.accept();
javascriptconfirm = myTestDriver.switchTo().alert();
javascriptconfirm = myTestDriver.switchTo().alert();
javascriptconfirm = myTestDriver.switchTo().alert();
origin: selenide/selenide

/**
 * Switch to window/tab by name/handle/title except some windows handles
 * @param title title of window/tab
 */
protected static WebDriver windowByTitle(WebDriver driver, String title) {
 Set<String> windowHandles = driver.getWindowHandles();
 for (String windowHandle : windowHandles) {
  driver.switchTo().window(windowHandle);
  if (title.equals(driver.getTitle())) {
   return driver;
  }
 }
 throw new NoSuchWindowException("Window with title not found: " + title);
}
origin: selenide/selenide

if (retryIfAlert) {
 try {
  Alert alert = webdriver.switchTo().alert();
  log.severe(e + ": " + alert.getText());
  alert.accept();
origin: TEAMMATES/teammates

/**
 * Closes the current browser window and switches back to the last window used previously.
 */
public void closeCurrentWindowAndSwitchToParentWindow() {
  driver.close();
  driver.switchTo().window(windowHandles.pop());
}
origin: TEAMMATES/teammates

public boolean isMsqWeightBoxFocused(int qnNumber, int choiceIndex) {
  WebElement weightBox = getMsqWeightBox(qnNumber, choiceIndex);
  return weightBox.equals(browser.driver.switchTo().activeElement());
}
origin: TEAMMATES/teammates

public boolean isMcqWeightBoxFocused(int qnNumber, int choiceIndex) {
  WebElement weightBox = getMcqWeightBox(qnNumber, choiceIndex);
  return weightBox.equals(browser.driver.switchTo().activeElement());
}
origin: TEAMMATES/teammates

public boolean isRubricSubQuestionBoxFocused(int qnNumber, int subQnIndex) {
  WebElement subQnBox = getRubricSubQuestionBox(qnNumber, subQnIndex);
  return subQnBox.equals(browser.driver.switchTo().activeElement());
}
origin: TEAMMATES/teammates

public boolean isMsqOtherWeightBoxFocused(int qnNumber) {
  WebElement weightBox = getMsqOtherWeightBox(qnNumber);
  return weightBox.equals(browser.driver.switchTo().activeElement());
}
origin: TEAMMATES/teammates

public boolean isRubricWeightBoxFocused(int qnNumber, int subQnIndex, int choiceIndex) {
  WebElement weightBox = getRubricWeightBox(qnNumber, subQnIndex, choiceIndex);
  return weightBox.equals(browser.driver.switchTo().activeElement());
}
origin: TEAMMATES/teammates

public boolean isMcqOtherWeightBoxFocused(int qnNumber) {
  WebElement weightBox = getMcqOtherWeightBox(qnNumber);
  return weightBox.equals(browser.driver.switchTo().activeElement());
}
origin: TEAMMATES/teammates

/**
 * Switches to new browser window for browsing.
 */
public void switchToNewWindow() {
  String curWin = driver.getWindowHandle();
  for (String handle : driver.getWindowHandles()) {
    if (!handle.equals(curWin) && !windowHandles.contains(curWin)) {
      windowHandles.push(curWin);
      driver.switchTo().window(handle);
      break;
    }
  }
}
origin: appium/java-client

  @Test public void listenableObjectSample() {
    try {
      ContextAware listenableContextAware =
          getEventFiringObject(contextAware, emptyWebDriver, contextListener, alertListener);
      WebDriver webDriver = listenableContextAware.context("NATIVE_APP");
      assertTrue(contextAwarePredicate.test(listenableContextAware));

      Alert alert = webDriver.switchTo().alert();
      assertTrue(alertPredicate.test(alert));

      assertTrue(webDriverPredicate.test(getEventFiringWebDriver(webDriver, searchingListener)));
    } finally {
      listeners.get(ContextListener.class).messages.clear();
      listeners.get(AlertListener.class).messages.clear();
      listeners.get(SearchingListener.class).messages.clear();
    }
  }
}
org.openqa.seleniumWebDriverswitchTo

Javadoc

Send future commands to a different frame or window.

Popular methods of WebDriver

  • findElement
    Find the first WebElement using the given method. This method is affected by the 'implicit wait' tim
  • get
    Load a new web page in the current browser window. This is done using an HTTP GET operation, and the
  • manage
    Gets the Option interface
  • quit
    Quits this driver, closing every associated window.
  • findElements
    Find all elements within the current page using the given mechanism. This method is affected by the
  • getCurrentUrl
    Get a string representing the current URL that the browser is looking at.
  • getPageSource
    Get the source of the last loaded page. If the page has been modified after loading (for example, by
  • getTitle
    The title of the current page.
  • navigate
    An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
  • close
    Close the current window, quitting the browser if it's the last window currently open.
  • getWindowHandles
    Return a set of window handles which can be used to iterate over all open windows of this WebDriver
  • getWindowHandle
    Return an opaque handle to this window that uniquely identifies it within this driver instance. This
  • getWindowHandles,
  • getWindowHandle,
  • <init>,
  • Close,
  • find_element,
  • findelement,
  • load,
  • navigateTo,
  • toString

Popular in Java

  • Running tasks concurrently on multiple threads
  • scheduleAtFixedRate (Timer)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Vector (java.util)
    The Vector class implements a growable array of objects. Like an array, it contains components that
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now