브라우저 창을 최대화하는 방법 Selenium

브라우저 최대화 Selenium

이 튜토리얼에서는 Selenium Webdriver를 사용하여 브라우저를 최대화, 최소화 또는 크기 조정하는 방법을 알아봅니다. 브라우저 크기를 조정하기 위한 maximize() 메서드와 차원을 사용하여 다양한 시나리오를 통해 설명합니다.

브라우저를 최대화하는 이유 Selenium 오토메이션?

브라우저가 최대화되지 않아 프레임워크가 실패하면 셀레늄에서 웹 애플리케이션의 요소를 인식하지 못할 수 있습니다. 따라서 브라우저 최대화는 셀레늄 프레임워크의 매우 중요한 부분입니다. 웹 애플리케이션을 자동화하는 동안 브라우저를 최대화하는 것이 좋습니다. 사용자가 셀레늄 프레임워크나 스크립트를 실행할 때 브라우저가 전체 화면 상태가 아닐 수 있으며 창 최대화를 사용하여 브라우저를 최대화해야 합니다. Selenium 웹 애플리케이션의 모든 요소를 ​​보려면 스크립트가 오류 없이 성공적으로 실행되도록 하려면 스크립트 시작 시 브라우저를 최대화하는 것이 좋습니다.

창을 최대화하는 단계 Selenium

브라우저를 최대화하는 방법은 다음과 같습니다. Selenium:

브라우저를 최대화하려면 Selenium, 최대화()를 호출해야 합니다. Selenium 드라이버 클래스의 창 인터페이스를 최대화하는 명령입니다.

void maximize() – This method is used to maximize the current browser.

창 최대화 Selenium
브라우저 최대화 Selenium

시나리오의 요구 사항에 따라 브라우저의 크기를 사용자 정의할 수 있습니다. Selenium webdriver는 브라우저를 최소화하는 방법을 제공하지 않으며 그러한 직접적인 방법도 없습니다. 브라우저를 최소화하려면 크기 조정 방법을 사용해야 합니다.

void setSize() – This method is used to set the size of the current browser.

Dimension getSize() – This method is used to get the size of the browser in height and width. It returns the dimension of the browser.

Point setPosition() – This method is used to set the position of the current browser.

Webdriver를 사용하여 브라우저 창을 최대화하는 방법

a) Selenium 설명이 포함된 스크립트입니다.

스크립트 Descript이온 : 아래에서 최대화 Selenium 표시된 스크립트는 다음을 사용하여 브라우저를 최대화합니다. testNG 프레임워크, 창 최대화 시나리오의 단계 Selenium 있습니다 :

  1. Chrome 브라우저를 엽니다.
  2. 사이트를 시작합니다.
  3. 브라우저 최대화를 보려면 몇 초 동안 기다리십시오. Selenium 행동 .
  4. 브라우저를 닫습니다.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Maximize {

	public static void main(String args[]) throws InterruptedException
	{
		WebDriver driver;
		
		System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe");
		 driver= new ChromeDriver();
 		 
         // Launch the application
     	 driver.get("https://www.guru99.com/");
     	 
     	     	//Resize current window to the set dimension
     	        driver.manage().window().maximize();
     	       
     	       //To Delay execution for 10 sec. as to view the maximize browser
     	        Thread.sleep(10000);
     	       
     	        //Close the browser
     	        driver.quit();
	}	
}

b) 산출물 분석

크롬 브라우저를 열고 브라우저를 최대화한 후 몇 초간 기다렸다가 브라우저를 닫았습니다.

Selenium Webdriver를 사용하여 브라우저 크기를 조정하는 방법

a) Selenium 설명이 포함된 스크립트입니다.

스크립트 Descript이온 : 아래에서 Selenium testNG 프레임워크를 사용하여 브라우저 크기를 조정하는 스크립트, 시나리오 단계는 다음과 같습니다.

  1. Chrome 브라우저를 엽니다.
  2. 사이트를 시작합니다.
  3. 크기 조정 작업을 보려면 몇 초 동안 기다리십시오.
  4. 브라우저를 닫습니다.
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Resize {

	public static void main(String args[]) throws InterruptedException
	{
		WebDriver driver;
	
		System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe");
		 driver= new ChromeDriver();
 		 
         // Launch the application
     	 driver.get("https://www.guru99.com/");
     	 
     	Dimension d = new Dimension(300,1080);
     	//Resize current window to the set dimension
     	   driver.manage().window().setSize(d);
     	        
     	 //To Delay execution for 10 sec. as to view the resize browser
     	 Thread.sleep(10000);
     	       
     	 //Close the browser
     	 driver.quit();
	}	
}

b) 산출물 분석

Chrome 브라우저를 열고 브라우저 크기를 조정한 후 몇 초 동안 기다렸다가 브라우저를 닫았습니다.

Webdriver를 사용하여 브라우저 창을 최소화하는 방법.

a) Selenium 설명이 포함된 스크립트입니다.

스크립트 Descript이온 : 아래에서 Selenium testNG 프레임워크를 사용하여 브라우저를 최소화하는 스크립트, 시나리오 단계는 다음과 같습니다.

  1. Chrome 브라우저를 엽니다.
  2. 사이트를 시작합니다.
  3. 최소화 작업을 보려면 몇 초간 기다리십시오.
  4. 브라우저를 닫습니다.
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Minimize {

	public static void main(String args[]) throws InterruptedException
	{
		WebDriver driver;
	
		System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe");
		 driver= new ChromeDriver();
 		 
         // Launch the application
     	 driver.get("https://www.guru99.com/");
     	 
     	Point p = new Point(0,3000);
     	
     	//Minimize the current window to the set position
     	        driver.manage().window().setPosition(p);
     	        
     	       //To Delay execution for 10 sec. as to view the minimize browser
     	        //you can view in the taskbar below of the screen.
     	        Thread.sleep(10000);
     	        
     	        //Close the browser
     	        driver.quit();
	}	
}

참고 : 이용자가 이용을 원하는 경우 Firefox 브라우저에서 사용자는 속성을 설정해야 합니다. Firefox드라이버 및 생성 Firefox아래 주어진 대로 위의 3가지 시나리오 스크립트에서 ChromeDriver 대신 드라이버 개체가 사용됩니다.

System.setProperty("webdriver.gecko.driver","E://Selenium//Selenium_Jars//geckodriver.exe ");
 driver= new FirefoxDriver();

b) 산출물 분석

크롬 브라우저를 열고 브라우저를 최소화한 후 몇 초간 기다렸다가 브라우저를 닫았습니다.

문제 해결

  • 최신 버전을 사용하세요 Selenium Jars, 크롬드라이버, 마리오네트 드라이버, IE드라이버 등
  • 사용하는 Selenium Jar와 브라우저의 호환성을 확인하세요.

요약

  • 위의 튜토리얼에서는 다양한 기능을 위해 프로젝트 프레임워크에서 필요에 따라 최대화, 최소화 및 크기 조정과 같은 다양한 시나리오를 통해 브라우저 크기 조정을 설명합니다.
  • 첫 번째 시나리오에서는 셀레늄에서 브라우저의 크기를 조정하는 방법을 보여주었습니다.
    Dimension d = new Dimension(300,1080);
    driver.manage().window().setSize(d);
    
  • 두 번째 시나리오에서는 다음을 보여주었습니다. Selenium 브라우저 창을 최대화합니다.
    driver.manage().window().maximize();
    
  • 세 번째 시나리오에서는 셀레늄으로 브라우저를 최소화하는 방법을 보여주었습니다.
    Point p = new Point(0,3000);     	
    driver.manage().window().setPosition(p);