갱스
selenium example 본문
실제 브라우저를 script로 컨트롤하는 라이브러리다
chrome이나 ie 드라이버에 연결하면
브라우저가 실행되고, 웹 페이지를 컨트롤할 수 있다
headless web browser인 PhantomJS도 컨트롤 가능하다
이 외에도 수많은 브라우저의 드라이버가 존재한다
Link : http://docs.seleniumhq.org/download/
보통 웹 페이지 테스트를 자동화하기 위해 많이들 사용하는데
한 벌의 소스로 여러 브라우저를 테스트할 수 있다!!
매크로를 만들 때도 써먹을 수 있다..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'pknam' | |
from selenium import webdriver | |
import time | |
def main(): | |
# browser = webdriver.PhantomJS(executable_path=r"D:\selenium_drivers\phantomjs-2.0.0-windows\bin\phantomjs.exe") | |
# browser = webdriver.Ie(executable_path=r"D:\selenium_drivers\Internet Explorer(x64)\IEDriverServer.exe") | |
browser = webdriver.Chrome(executable_path=r"D:\selenium_drivers\Chrome(x86)\chromedriver.exe") | |
browser.get("http://www.naver.com/") | |
# wait for page loading | |
time.sleep(1) | |
browser.save_screenshot('screenshot1.png') | |
# input search keyword | |
browser.find_element_by_id('query').send_keys('hahaha') | |
browser.find_element_by_id('search_btn').click() | |
# wait for page loading | |
time.sleep(1) | |
browser.save_screenshot('screenshot2.png') | |
browser.quit() | |
if __name__ == "__main__": | |
main() | |
드라이버를 몇 개 받아 써봤는데
IE만 유독 send_keys() 함수 작동이 느리다
'Python' 카테고리의 다른 글
boost::python Embedding (0) | 2017.12.17 |
---|---|
[Python] decorator (0) | 2015.08.04 |