don't stop believing

Chrome 브라우저 창 크기 조절 과 뒤로가기 앞으로 가기 본문

Testing Automation/Selenium

Chrome 브라우저 창 크기 조절 과 뒤로가기 앞으로 가기

Tongchun 2018. 3. 22. 18:57

selenium을 하면서 굳이~~ 창을 크게 하고 싶다면 두 가지 방법이 있습니다.

chrome option을 사용하는 방법과 maximize_window() 함수와 set_window_size() 함수를 사용하는 방법입니다.


chrome option을 사용하기 위해서는 Options 모듈을 아래와 같이 추가해야 합니다.

from selenium.webdriver.chrome.options import Options


먼저 chrome을 전체화면으로 키우는 옵션입니다. chrome에서 F11 키를 누르는 것과 동일합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
# chrome F11 .
options.add_argument('--kiosk')
# executable_path chromedriver , chrome_options options .
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=options)
# google .
driver.get('https://google.com')
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


다음은 전체 화면으로 키우는 옵션입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
# chrome .
options.add_argument('--start-fullscreen')
# executable_path chromedriver , chrome_options options .
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=options)
# google .
driver.get('https://google.com')
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Chrome 창을 원하는 넓이와 높이로 조정할 수 있습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
# executable_path chromedriver , chrome_options options .
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=options)
# chrome .
driver.set_window_size(1024, 600)
# google .
driver.get('https://google.com')
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

브라우저에서 뒤로 가기와 앞으로 가기는 back()forward() 함수로 할 수 있습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import time
from selenium import webdriver
# Chrome WebDriver Chrome .
driver = webdriver.Chrome('./chromedriver')
# www.google.com .
driver.get('http://www.google.com')
time.sleep(2)
# html element q . ()
inputElement = driver.find_element_by_name('q')
time.sleep(2)
# 'www.ngle.co.kr' .
inputElement.send_keys('ngle')
time.sleep(2)
# .
inputElement.submit()
time.sleep(2)
# 'THE BEST BUSINESS PLAN' .
continue_link = driver.find_element_by_partial_link_text('THE BEST BUSINESS PLAN')
time.sleep(2)
# .
continue_link.click()
time.sleep(5)
# . ( .)
driver.back()
time.sleep(5)
# ngle .
driver.forward()
time.sleep(5)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

여기까지 창 크기 조절과 뒤로가기, 앞으로가기 였습니다.


'Testing Automation > Selenium' 카테고리의 다른 글

Selenium으로 Alert 창 처리하기  (1) 2018.11.01
selenium과 Unittest 같이 사용하기  (0) 2018.03.28
iframe 처리하기  (4) 2018.03.22
element highlight로 확인해 보기  (0) 2018.03.22
Chrome에서 Tab 변경하기  (0) 2018.03.21
Comments