[英]Closing the Window after Some Time in Selenium Java
Using Selenium I am opening a window.使用 Selenium 我正在打开 window。 I want to close and Quit the Window after the Button is Clicked.
单击按钮后,我想关闭并退出 Window。 How can I achieve that in Selenium.
我怎样才能在 Selenium 中实现这一点。 The function which I want to perform before Closing The window is Below
我想在关闭之前执行的 function window 如下
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='css-vote-button pds-vote-button' and starts-with(@id, 'pd-vote-button10359300')]/span[text()='Vote']"))).click();
With driver.close()
you can close the tab/window which WebDriver controlling.使用
driver.close()
您可以关闭 WebDriver 控制的选项卡/窗口。
I use this code to close all tabs/windows.我使用此代码关闭所有选项卡/窗口。
var tabs = new ArrayList<>(driver.getWindowHandles());
while(tabs.size() > 0){
driver.switchTo().window(tabs.get(0)); //NoSuchWindowException
driver.close();
tabs = new ArrayList<>(driver.getWindowHandles());
}
To close & quit your driver session, you can implement the following:要关闭并退出您的驱动程序 session,您可以执行以下操作:
Thread.Sleep(10000) // or Thread.Sleep(TimeSpan.FromSeconds(10));
Driver.Close();
Driver.Quit();
Thread.Sleep
simply implements 10 second wait, Driver.Close
closes your browser session, and Driver.Quit
terminates the instance of WebDriver. Thread.Sleep
只是实现了 10 秒的等待, Driver.Close
关闭浏览器 session, Driver.Quit
终止 WebDriver 的实例。 Both are necessary in order to properly terminate a session.为了正确终止 session,两者都是必要的。
It is recommended that you wrap these methods in a try / finally block to avoid any errors with terminating the session.建议您将这些方法包装在 try / finally 块中,以避免在终止 session 时出现任何错误。
if (Driver != null)
{
try { Driver?.CloseApp(); }
finally
{
try
{
Driver?.Quit();
}
finally
{
Driver = null;
DriverFactory.Current.StopAppiumServer();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.