Download Python에서 OS에 맞게 설치한다.
-> pip란? package installer for python: python의 여러 패키지를 쉽게 설치하고 관리하게 해주는 역할
-> mac의 brew나 ubuntu의 apt-get과 같은 패키지 관리 툴임
pip3 install -U selenium
chromedriver.chromium.org에서 OS에 맞게 다운로드한다.
webdriver를 간단히 실습해보았다.
다운받은 드라이버를 /drivers
안에 넣어주고, 다음과 같은 코드를 실행한다.
from selenium import webdriver
import time
driver = webdriver.Chrome("/Users/kimwookyoung/Desktop/2021/2021-1/소공/selenium-demo/drivers/chromedriver")
driver.implicitly_wait(10)
driver.get("http://google.com")
driver.find_element_by_name("q").send_keys("Hongik University")
driver.find_element_by_name("btnK").click()
driver.maximize_window()
driver.refresh()
time.sleep(2)
driver.quit()
print("Test Completed")
from selenium import webdriver
import HtmlTestRunner
import unittest
import time
class DemoUnitTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome("/Users/kimwookyoung/Desktop/2021/2021-1/소공/selenium-demo/drivers/chromedriver")
cls.driver.implicitly_wait(10)
cls.driver.maximize_window()
def test_GoogleSearch_Hongik(self):
self.driver.get("https://google.com")
self.driver.find_element_by_name("q").send_keys("HongikUniversity")
self.driver.find_element_by_name("btnK").click()
@classmethod
def tearDownClass(cls):
time.sleep(3)
cls.driver.close()
cls.driver.quit()
print("Test Done Successfully!")
if __name__ == '__main__':
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='/Users/kimwookyoung/Desktop/2021/2021-1/소공/selenium-demo/reports'))