任何人都可以告诉我如何使用webdriver关闭除第一个选项卡/主选项卡以外的所有打开的选项卡?
我在下面尝试过,但它也关闭了所有标签,包括第一个标签.
public static void closeTabs() {
String wh1=driver.getWindowHandle();
String cwh=null;
while(wh1!=cwh)
{
new Actions(driver).sendKeys(Keys.CONTROL).sendKeys(Keys.NUMPAD1).perform();
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL, Keys.TAB);
cwh=driver.getWindowHandle();
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL+"w");
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我.
我想关闭所有打开的选项卡(浏览器窗口)而不实际关闭驱动程序,因为我想继续使用它。
driver.close()只会关闭聚焦的选项卡。
driver.quit() 将关闭它们,但也会退出驱动程序。
我想过使用driver.quit()然后重新打开驱动程序。但是好像不是很干净。或者它可能是超级干净的,但也是一件很慢的事情。
注意:通过geckodriver使用 Firefox
我该如何解决这个问题?
最近,在使用 selenium firefox 驱动程序时遇到了这个问题。提前致谢
设置
os.name: 'Mac OS X',
os.arch: 'x86_64',
os.version: '10.12.6',
java.version: '1.8.0_131'
Firefox 版本56.0.1(64 位)
Gecko 驱动程序 最新 0.19.0
错误显示失败:org.openqa.selenium.SessionNotCreatedException:试图在没有建立连接的情况下运行命令
我尝试了不同的方法来解决它,但总是出现相同的错误。1.更新所有selenium测试驱动到最新2.指定目录export PATH = $PATH driverDir
我的代码
package automationFramework;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class GeckoDriver {
private static WebDriver driver;
public static int random = 0;
private String baseURL;
// @BeforeClass : Executes only once …Run Code Online (Sandbox Code Playgroud)