本文整理了Java中org.openqa.selenium.WebDriver.getWindowHandles()
方法的一些代码示例,展示了WebDriver.getWindowHandles()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebDriver.getWindowHandles()
方法的具体详情如下:
包路径:org.openqa.selenium.WebDriver
类名称:WebDriver
方法名:getWindowHandles
[英]Return a set of window handles which can be used to iterate over all open windows of this WebDriver instance by passing them to #switchTo(). Options#window()
[中]返回一组窗口句柄,通过将它们传递给#switchTo(),这些句柄可用于迭代此WebDriver实例的所有打开窗口。选项#窗口()
代码示例来源: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: 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: 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
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: 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 Set<String> getWindowHandles() {
// TODO Auto-generated method stub
return driver.getWindowHandles();
}
代码示例来源:origin: ru.stqa.selenium/webdriver-factory
@Override
public boolean isAlive(WebDriver driver) {
try {
return driver.getWindowHandles().size() > 0;
} catch (UnhandledAlertException ex) {
return true;
} catch (WebDriverException ex) {
return false;
}
}
}
代码示例来源:origin: io.selendroid/selendroid-client
public Set<String> call() throws Exception {
Set<String> handles = driver.getWindowHandles();
if (handles.size() == count) {
return handles;
}
return null;
}
};
代码示例来源:origin: stackoverflow.com
// wait for a new window and switch to it
driver.switchTo().window(wait.until(new ExpectedCondition<String>() {
@Override
public String apply(WebDriver drv) {
for (String handle : drv.getWindowHandles()){
if (!handle.equals(mainHandle))
return handle;
}
return null;
}
}));
代码示例来源:origin: stackoverflow.com
public static boolean selectWindow(WebDriver driver, String windowTitle){
//Search ALL currently available windows
for (String handle : driver.getWindowHandles()) {
String newWindowTitle = driver.switchTo().window(handle).getTitle();
if(newWindowTitle.equalsIgnoreCase(windowTitle))
//if it was found break out of the wait
return true;
}
return false;
}
代码示例来源:origin: org.mazarineblue/MazarineBlue-WebDriver
void closeAllHandles() {
for (WindowHandle handle : popups.values())
closeHandle(handle);
popups.clear();
windowHandles = driver.getWindowHandles();
}
代码示例来源:origin: org.mazarineblue/MazarineBlue-WebDriver
void closeHandle(String popupName) {
WindowHandle handle = popups.get(popupName);
closeHandle(handle);
popups.remove(popupName);
windowHandles = driver.getWindowHandles();
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("http://stackoverflow.com");
WebElement element = driver.findElement(By.linkText("Stack Overflow"));
// set the target _blank on the link
((JavascriptExecutor)driver).executeScript("arguments[0].target='_blank';", element);
// click the link
element.click();
// set the context to the new window
driver.switchTo().window(driver.getWindowHandles().toArray()[1]);
代码示例来源:origin: persado/stevia
@Override
public void switchToLatestWindow() {
Iterator<String> itr = driver.getWindowHandles().iterator();
String lastElement = null;
while (itr.hasNext()) {
lastElement = itr.next();
}
driver.switchTo().window(lastElement);
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("http://stackoverflow.com");
// open a new window
((JavascriptExecutor)driver).executeScript("window.open(window.location.href, '_blank');");
// set the context to the new window
driver.switchTo().window(driver.getWindowHandles().toArray()[1]);
// click the link
driver.findElement(By.linkText("Stack Overflow")).click();
代码示例来源:origin: org.jspringbot/jspringbot-selenium
public List<String> getWindowHandles() {
List<String> handles = new ArrayList<String>(driver.getWindowHandles());
LOG.keywordAppender() .appendArgument("Handles", handles);
return handles;
}
代码示例来源: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: net.serenity-bdd/core
public void close() {
if (proxyInstanciated()) {
//if there is only one window closing it means quitting the web driver
if (getDriverInstance().getWindowHandles() != null && getDriverInstance().getWindowHandles().size() == 1){
this.quit();
} else{
getDriverInstance().close();
}
webDriverFactory.shutdownFixtureServices();
}
}
代码示例来源:origin: tarun3kumar/seleniumtestsframework
public final void selectWindow() throws NotCurrentPageException {
TestLogging.logWebStep(
"select window, locator={\"" + getPopupWindowName() + "\"}", false);
// selectWindow(getPopupWindowName());
driver.switchTo().window((String)
driver.getWindowHandles().toArray()[0]);
waitForSeconds(1);
// Check whether it's the expected page.
assertCurrentPage(true);
}
代码示例来源:origin: EnMasseProject/enmasse
public ConsoleWebPage clickOnDashboard(String namespace, AddressSpace addressSpace) throws Exception {
openOpenshiftPage();
clickOnShowAllProjects();
selenium.clickOnItem(getProjectListItem(namespace), namespace);
waitForRedirectToService();
ProvisionedServiceItem serviceItem = getProvisionedServiceItem();
serviceItem.collapseServiceItem();
selenium.clickOnItem(serviceItem.getRedirectConsoleButton());
Set<String> tabHandles = selenium.getDriver().getWindowHandles();
selenium.getDriver().switchTo().window(tabHandles.toArray()[tabHandles.size() - 1].toString());
return new ConsoleWebPage(selenium, addressApiClient, addressSpace);
}
内容来源于网络,如有侵权,请联系作者删除!