포워드 드라이버 방식 – Selenium Python
이 기술은 웹 브라우저 기록에서 앞으로 탐색하는 데 사용되며 Selenium이 새로운 탐색 명령을 실행하여 브라우저 기록 페이지에서 앞으로 이동할 수 있도록 합니다.
Selenium Python의 이 순방향 드라이버 방법은 자동화된 테스트 스크립트의 효율성과 정확성을 향상시킬 수 있습니다. 사이를 빠르게 이동할 수 있습니다.
설정
Firefox 실행 파일
여기에서 Firefox 브라우저 설치 프로그램을 다운로드하세요.
다운로드한 후 브라우저를 설치하면 exe 파일이 C:\Program Files\Mozilla Firefox\firefox.exe에 자동으로 저장됩니다. 나중에 필요할 것입니다.
게코 드라이버
Windows 사용자는 여기에서 gecko 드라이버를 다운로드할 수 있습니다. 다른 버전의 경우 릴리스를 참조하세요.
zip의 압축을 풀고 “geckodriver.exe” 파일을 C:\ 디렉터리에 넣습니다. 나중에 코드에서 이를 참조할 것입니다.
셀레늄 Python 패키지
우리는 최신 버전의 Selenium Webdriver로 작업할 예정이므로 다음을 pip 설치하십시오.
pip3 install -U selenium
pip3 install -U webdriver-manager
연산
Selenium에서 필요한 모듈 가져오기
Options() 함수를 사용하여 Firefox 바이너리 위치 설정
Firefox() 함수의 실행 가능_경로 매개변수를 사용하여 Firefox 드라이버 경로 설정
get() 함수를 사용하여 Firefox 드라이버를 실행하고 첫 번째 웹사이트를 엽니다.
두 번째 웹사이트로 이동하고 페이지 제목을 인쇄하려면 전달() 메서드를 사용하세요.
예
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
options = Options()
# you need to download and install firefox and it will be in the following path
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
# you need to download and install geckodriver.exe and put it in the same folder as this script
driver = webdriver.Firefox(executable_path=r'C:\geckodriver.exe', options=options)
# launch driver using the selenium webdriver and open first website
driver.get('https://tutorialspoint.com/selenium/selenium_automation_practice.htm')
print(f"Loaded first page. Title of the page is : {driver.title}")
# instruct driver using the selenium webdriver to open the second website
driver.get('https://www.tutorialspoint.com/python3/index.htm')
# step one step forward browser history
driver.forward()
print(f"Loaded second page. Title of the page is : {driver.title}")
산출
콘솔에 진행 상황이 표시됩니다.
Loaded first page. Title of the page is : Selenium - Automation Practice
Form
Loaded second page. Title of the page is : Python 3 Tutorial
1. 첫 번째 페이지가 로드되었습니다.
2. 두 번째 페이지가 로드되었습니다.
Selenium에서 필수 모듈을 가져온 다음 Firefox 브라우저에 대한 옵션을 설정하십시오.
바이너리 위치는 Firefox 실행 파일의 경로를 사용하여 설정됩니다. 드라이버는 Selenium이 Firefox 브라우저와 상호 작용하는 데 필요한 GeckoDriver 실행 파일의 경로를 사용하여 설정됩니다.
드라이버는 get() 함수를 사용하여 시작되어 첫 번째 웹 사이트를 열고 페이지 제목이 콘솔에 인쇄됩니다.
그런 다음 드라이버는 get() 함수를 사용하여 두 번째 웹사이트로 이동하라는 지시를 받습니다.
앞으로() 메소드는 다음 페이지로 넘어갑니다.
결론
Selenium Python Forward Driver Method는 자동화된 테스트 스크립트의 효율성과 정확성을 크게 향상시킬 수 있는 강력한 접근 방식입니다. 새로운 탐색 명령을 실행하지 않고도 Selenium WebDriver API에서 제공하는 "forward()" 메서드를 활용하면 브라우저 기록을 쉽게 탐색할 수 있습니다. 이렇게 하면 테스트 스크립트의 전반적인 성능이 향상되고 시간이 절약됩니다. 이 블로그에서는 Selenium Python에서 Forward Driver Method를 활용하는 이점과 이를 테스트 스크립트에 포함하는 방법에 대한 자세한 지침을 설명했습니다.

