Selenium 설치 테스트 환경:Linux Ubuntu, Firefox java -jar selenium-server-standalone-2.35.0.jar pip install -U selenium
5.
샘플 #1 from seleniumimport webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys import time browser = webdriver.Firefox() # Get local session of firefox browser.get("http://www.yahoo.com") # Load page assert "Yahoo!" in browser.title elem = browser.find_element_by_name("p") # Find the query box elem.send_keys("seleniumhq" + Keys.RETURN) time.sleep(0.2) # Let the page load, will be added to the API try: browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]").click() except NoSuchElementException: assert 0, "can't find seleniumhq" browser.close()
select/option tag select =driver.find_element_by_name("txtPsgFlg_1") options = select.find_elements_by_tag_name("option") for option in options: if num == option.get_attribute("value"): option.click()
Tip 1. Selenium IDE를사용하면 정보를 찾기 쉽다. 2. 적절한 딜레이를 줘야 정상적으로 동작한다. 3. 예외 처리를 잘 해둬야 한다.
17.
결론 1. 이번 기차표예매는 큰 도움은 안됬음. - 서버가 뻗어서 일단 예상대로 동작 안함. 2. 페이지 소스가 자주 바뀌면 이에 따라 계속 수 정이 필요함. 3. 그럼에도 불구하고, 배우고 쓸만한 가치가 있 음. 웹 UI 테스트 자동화등 - 실제 서비스 테스트 사례도 많음.