Javascript
 Computer >> コンピューター >  >> プログラミング >> Javascript

close()とquit()の違いを説明します


close()メソッドとquit()メソッドの違いを以下に示します。つまり、どちらの方法でもブラウザが閉じ、パラメータは必要ありません。

シリアル番号
close()
quit()
1
close()メソッドは、フォーカスのあるブラウザを閉じます。
quit()メソッドは、すべてのブラウザーを閉じます。
2
close()メソッドは、アクティブなWebDriverインスタンスを閉じます。
quit()メソッドは、すべてのアクティブなWebDriverインスタンスを閉じます。

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.Set;
import java.util.Iterator;
import org.testng.annotations.Test
public class WindowHandles{
   @Test
   public void Browserclose_quit() throws Exception {
      System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      driver.get("https://www.tutorialspoint.com/index.htm");
      String currentwindow = driver.getWindowHandle();
      Set<String> allWindows = driver.getWindowHandles();
      Iterator<String> i = allWindows.iterator();
      while(i.hasNext()){
         String childwindow = i.next();
         if(!childwindow.equalsIgnoreCase(currentWindow)){
            driver.switchTo().window(childwindow);
            System.out.println("The child window is "+childwindow);
            // close() method shall the close the child window which
            //is the browser in focus
            //the parent window shall still be open
            driver.close()
         } else {
            System.out.println("There are no children");
         }
      }
      // quit() will close all the active webdriver instances, so now the parent //window will close       driver.quit();
   }
}

  1. ビットコインとイーサリアムの違い

    2017年は間違いなく暗号通貨の年であり、価格が下がったとしても、特に主要通貨への関心は下がっていません。最も人気のある2つの通貨であるビットコインとイーサリアムは、年間で大幅な価格上昇を見せました。それぞれ、1,000ドル未満から20,000ドル近く、10ドル未満から1,300ドル超になりました。暗号通貨への投資に興味がある場合は、ビットコインとイーサリアムの違いについて簡単に説明します。 1。ビットコインはジェネレーション1、イーサリアムはジェネレーション2 ビットコインは、世間の注目を集めた最初の主要な暗号通貨でした。ある意味、初代です。イーサリアムは数年後に登場し、ビットコインをベ

  2. Windows 10 と Windows 11 の違いは?

    Microsoft は最新の Windows 11 をリリースし、多くの新機能と改善を行いました。また、多くのパッチとアップデートにより、Windows 10 は新しい Windows 11 よりも安定した OS になりました。同社によると、2025 年以降に Windows 10 でのサポートが終了するため、Windows 11 または Windows 10 へのアップグレードを決定するのに十分な時間があります。 Windows 10 を快適に使用してください。この記事では、Windows 10 と Windows 11 の比較を用意しました。 新しい OS に切り替えるか、Windows