本文整理汇总了Java中org.openqa.selenium.WebDriver.close方法的典型用法代码示例。如果您正苦于以下问题:Java WebDriver.close方法的具体用法?Java WebDriver.close怎么用?Java WebDriver.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.WebDriver
的用法示例。
在下文中一共展示了WebDriver.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeOthers
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Override
public void closeOthers()
{
String currentTitle = getTitle();
String currentWinHandle = engine.getDriver().getWindowHandle();
for(String winHandle : engine.getDriver().getWindowHandles())
{
WebDriver itemDrive = engine.getDriver().switchTo().window(winHandle);
if(!itemDrive.getTitle().equals(currentTitle))
{
itemDrive.close();
}
}
engine.getDriver().switchTo().window(currentWinHandle);
}
示例2: closeWinByUrlStartWith
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
* 关闭url以指定字符串开头的window
* @param phoenix 引擎
* @param params 参数
*/
public static void closeWinByUrlStartWith(Phoenix phoenix, String[] params)
{
String startWith = params[0];
WebDriver driver = phoenix.getEngine().getDriver();
Set<String> handles = driver.getWindowHandles();
Iterator<String> handleIt = handles.iterator();
String currentHandle = driver.getWindowHandle();
while(handleIt.hasNext())
{
String handle = handleIt.next();
driver.switchTo().window(handle);
if(driver.getCurrentUrl().startsWith(startWith))
{
driver.close();
break;
}
}
driver.switchTo().window(currentHandle);
}
示例3: main
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception{
//配置ChromeDiver
System.getProperties().setProperty("webdriver.chrome.driver", "chromedriver.exe");
//开启新WebDriver进程
WebDriver webDriver = new ChromeDriver();
//全局隐式等待
webDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//设定网址
webDriver.get("https://passport.weibo.cn/signin/login?entry=mweibo&res=wel&wm=3349&r=http%3A%2F%2Fm.weibo.cn%2F");
//显示等待控制对象
WebDriverWait webDriverWait=new WebDriverWait(webDriver,10);
//等待输入框可用后输入账号密码
webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("loginName"))).sendKeys(args[0]);
webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("loginPassword"))).sendKeys(args[1]);
//点击登录
webDriver.findElement(By.id("loginAction")).click();
//等待2秒用于页面加载,保证Cookie响应全部获取。
sleep(2000);
//获取Cookie并打印
Set<Cookie> cookies=webDriver.manage().getCookies();
Iterator iterator=cookies.iterator();
while (iterator.hasNext()){
System.out.println(iterator.next().toString());
}
//关闭WebDriver,否则并不自动关闭
webDriver.close();
}
示例4: testSelenium
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static void testSelenium() throws Exception {
System.getProperties().setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
webDriver.get("http://huaban.com/");
Thread.sleep(5000);
WebElement webElement = webDriver.findElement(By.xpath("/html"));
System.out.println(webElement.getAttribute("outerHTML"));
webDriver.close();
}
示例5: closeDrivers
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
* Quits all of the web drivers in the list.
*/
private void closeDrivers() {
for (WebDriver webDriver : this.webDriverList)
try {
// Open about:config in case of fennec (Firefox for Android) and close.
if (((RemoteWebDriver) webDriver).getCapabilities().getBrowserName().equalsIgnoreCase("fennec")) {
webDriver.get("about:config");
webDriver.close();
} else {
webDriver.quit();
}
} catch (Exception e) {
logger.error("closing driver:", e);
}
}
示例6: main
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static void main(String[] args) {
setupDriverExecutable("chromedriver", "webdriver.chrome.driver");
WebDriver driver = new ChromeDriver();
try {
crawl(driver);
} catch (Exception e){
System.out.println("ERROR: "+e.getMessage());
e.printStackTrace();
}
driver.close();
}
示例7: finishTest
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static void finishTest(WebDriver driver){
if (System.getenv().get("TRAVIS_JOB_NUMBER") != null) {
SauceREST sauceRest = new SauceREST(System.getenv().get("SAUCE_USERNAME"), System.getenv().get("SAUCE_ACCESS_KEY"));
sauceRest.jobPassed((((RemoteWebDriver) driver).getSessionId()).toString());
}
driver.close();
driver.quit();
}
示例8: handleNewSnap
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
private byte[] handleNewSnap(final String id, final String size) throws IOException, TimeoutException {
final EmbeddableData data = getAvailablePlotList()
.stream()
.filter(x -> x.getIdentifier().equals(id))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("The request " + id + " is not available"));
final WebDriver webDriver = webDriver();
try (Jedis jedis = jedisPool.getResource()) {
final Page pageHandler = fromId(id);
final ScreenShotService.Builder builder = new ScreenShotService
.Builder()
.setPageHandler(pageHandler)
.jedis(jedis)
.id(id)
.webDriver(webDriver)
.plotUrl(new URL(data.getIframeUrl()))
.ttl(Integer.parseInt(properties.getProperty("caching.ttl")))
.timeout(30);
if (!size.equals(ORIGINAL_SIZE))
builder.geometry(Geometry.fromString(size));
final ScreenShotService service = builder.build();
service.perform();
return service.fetch(id, size);
} finally {
try {
if (webDriver != null) {
webDriver.close();
webDriver.quit();
}
} catch (Exception ex) {
//Ignored
}
}
}
示例9: returnToPool
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public void returnToPool(WebDriver webDriver) {
if (shutdowned.get()) {
webDriver.quit();
webDriver = null;
} else {
Set<String> handles = webDriver.getWindowHandles();
if (handles.size() > 1) {
int index = 0;
for (String handle : handles) {
if (index == 0) {
index++;
continue;
}
WindowUtil.changeWindowTo(webDriver, handle);
webDriver.close();
index++;
}
}
synchronized (shutdowned) {
if(!shutdowned.get()){
innerQueue.add(webDriver);
}else{
webDriver.quit();
webDriver = null;
}
}
}
}