org.openqa.selenium.WebDriver.getWindowHandle()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中org.openqa.selenium.WebDriver.getWindowHandle()方法的一些代码示例,展示了WebDriver.getWindowHandle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebDriver.getWindowHandle()方法的具体详情如下:
包路径:org.openqa.selenium.WebDriver
类名称:WebDriver
方法名:getWindowHandle

WebDriver.getWindowHandle介绍

[英]Return an opaque handle to this window that uniquely identifies it within this driver instance. This can be used to switch to this window at a later date
[中]返回此窗口的不透明句柄,该句柄在此驱动程序实例中唯一标识该窗口。这可用于以后切换到此窗口

代码示例

代码示例来源:origin: selenide/selenide

private File clickAndInterceptFileByProxyServer(WebElementSource anyClickableElement, WebElement clickable,
                    SelenideProxyServer proxyServer, long timeout) throws FileNotFoundException {
 Config config = anyClickableElement.driver().config();
 WebDriver webDriver = anyClickableElement.driver().getWebDriver();
 String currentWindowHandle = webDriver.getWindowHandle();
 Set<String> currentWindows = webDriver.getWindowHandles();
 FileDownloadFilter filter = proxyServer.responseFilter("download");
 filter.activate();
 try {
  clickable.click();
  waiter.wait(filter, new HasDownloads(), timeout, config.pollingInterval());
  return firstDownloadedFile(anyClickableElement, filter, timeout);
 }
 finally {
  filter.deactivate();
  closeNewWindows(webDriver, currentWindowHandle, currentWindows);
 }
}

代码示例来源:origin: org.finra.jtaf/jtaf-extwebdriver

/**
 * Returns the current window handle ID
 * 
 * @return the window handle ID
 */
@Override
public String getWindowId() {
  return wd.getWindowHandle();
}

代码示例来源: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: com.wso2telco.test/uitest-framework

@Override
public String getWindowHandle() {
  // TODO Auto-generated method stub
  return driver.getWindowHandle();
}

代码示例来源:origin: stackoverflow.com

String oldTab = driver.getWindowHandle();

public static void switchingToNewTabUsingid(WebDriver driver,WebDriverWait wait,String id,String oldTab)
  {
    wait.until(ExpectedConditions.elementToBeClickable(By.id(id)));
    driver.findElement(By.id(id)).click();
    ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
    newTab.remove(oldTab);
    driver.switchTo().window(newTab.get(0));
  }

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

@Override
public String getWindowHandle() {
  try {
    return webDriver.getWindowHandle();
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: qaprosoft/carina

public void switchWindow() throws NoSuchWindowException {
  WebDriver drv = getDriver();
  Set<String> handles = drv.getWindowHandles();
  String current = drv.getWindowHandle();
  if (handles.size() > 1) {
    handles.remove(current);
  }
  String newTab = handles.iterator().next();
  drv.switchTo().window(newTab);
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-test-lib

/**
 * {@inheritDoc}.
 */
@Override
public String getWindowHandle() {
  waitForPageReady();
  return driver.getWindowHandle();
}

代码示例来源:origin: fhoeben/hsac-fitnesse-fixtures

public int getCurrentTabIndex(List<String> tabHandles) {
  try {
    String currentHandle = driver().getWindowHandle();
    return tabHandles.indexOf(currentHandle);
  } catch (NoSuchWindowException e) {
    return -1;
  }
}

代码示例来源:origin: viltgroup/minium

@Override
public String getWindowHandle() {
  ensureSwitch();
  return webDriver.getWindowHandle();
}

代码示例来源:origin: vmi/selenese-runner-java

/**
 * Set WebDriver.
 *
 * @param driver WebDriver.
 */
public void setDriver(WebDriver driver) {
  this.driver = driver;
  this.initialWindowHandle = driver.getWindowHandle();
  setDriverTimeout();
}

代码示例来源:origin: com.comcast.magic-wand/core

/**
 * {@inheritDoc}
 */
public String getWindowHandle() {
  WebDriver driver = this.getDriver();
  String windowHandle = null;
  if (null != driver) {
    windowHandle = driver.getWindowHandle();
  }
  return windowHandle;
}

代码示例来源:origin: org.seleniumhq.webdriver/webdriver-selenium

public WebDriverBackedSelenium(WebDriver baseDriver, String baseUrl) {
 setUpElementFindingStrategies();
 setUpOptionFindingStrategies();
 setUpTextMatchingStrategies();
 this.driver = baseDriver;
 if (baseUrl.endsWith("/")) {
  this.baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
 } else {
  this.baseUrl = baseUrl;
 }
 originalWindowHandle = driver.getWindowHandle();
}

代码示例来源:origin: net.serenity-bdd/core

public String getWindowHandle() {
  if (!isEnabled()) {
    return StringUtils.EMPTY;
  }
  return getProxiedDriver().getWindowHandle();
}

代码示例来源:origin: net.thucydides/thucydides-core

public String getWindowHandle() {
  if (!isEnabled()) {
    return StringUtils.EMPTY;
  }
  return getProxiedDriver().getWindowHandle();
}

代码示例来源:origin: org.jspringbot/jspringbot-selenium

public String getWindowHandle() {
  String handle = driver.getWindowHandle();
  LOG.keywordAppender().appendArgument("Handle", handle);
  return handle;
}

代码示例来源:origin: com.daveayan/gherkinsalad.core

/**
 * Use this method to actually launch the browser window that is represented by this object.
 */
public void launch() {
  BrowserFactory _launcher = (BrowserFactory) ReflectionUtils.objectFor(Config.getProperty("browser." + this.name.toLowerCase().trim() + ".class"));
  instance = _launcher.getDriver();
  default_window_handle = instance.getWindowHandle();
}

代码示例来源:origin: net.serenity-bdd/serenity-core

public String getWindowHandle() {
  if (!isEnabled()) {
    return StringUtils.EMPTY;
  }
  return getProxiedDriver().getWindowHandle();
}

代码示例来源:origin: com.axway.ats.framework/ats-uiengine

public AbstractHtmlEngine( UiDriver uiDriver,
              AbstractElementsFactory elementsFactory ) {
  super(uiDriver, elementsFactory);
  AbstractHtmlDriver htmlDriver = (AbstractHtmlDriver) uiDriver;
  webDriver = (WebDriver) htmlDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
  mainWindowHandle = webDriver.getWindowHandle();
}

代码示例来源:origin: org.seleniumhq.webdriver/webdriver-remote-server

public ResultType call() throws Exception {
 response = newResponse();
 response.setValue(getDriver().getWindowHandle());
 return ResultType.SUCCESS;
}

相关文章