py+webdriver学习之旅3:checkbox
从今天开始,开始复习虫师的py+webdriver,http://www.cnblogs.com/fnng/category/349036.html,我将在虫师的教程之后,开始写点进阶的,比如page object,这种知识~
__author__ = 'Administrator' from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import os import time from selenium.webdriver.support.ui import WebDriverWait driver=webdriver.Firefox() file_path='file:///'+os.path.abspath('checkbox.html') driver.get(file_path) checkboxes=driver.find_elements_by_css_selector("input[type=checkbox]") for checkbox in checkboxes: checkbox.click() time.sleep(2) print len(driver.find_elements_by_css_selector('input[type=checkbox]')) time.sleep(2) #把页面上最后一个checkbox的勾去掉 driver.find_elements_by_css_selector('input[type=chechbox]').pop().click() #WebDriverWait(driver,10).until(lambda the_driver ) driver.quit()