Python+Selenium 自动化实现实例-定位一组对象(checkbox,inputs)


# -*- coding: utf-8 -*-
from selenium import webdriver import time import os dr = webdriver.Chrome() file = os.path.abspath("c:\\Temp\\checkbox.html") #获取文件路径
dr.get(file) # 选择所有的checkbox并全部勾上
 checkboxes = dr.find_elements_by_css_selector('input[type=checkbox]') for checkbox in checkboxes: checkbox.click() time.sleep(1) dr.refresh() time.sleep(2) # 打印当前页面上有多少个checkbox
print len(dr.find_elements_by_css_selector('input[type=checkbox]')) # 选择页面上所有的input,然后从中过滤出所有的checkbox并勾选之
inputs = dr.find_elements_by_tag_name('input') for input in inputs: if input.get_attribute('type') == 'checkbox': input.click() time.sleep(1) # 把页面上最后1个checkbox的勾给去掉
dr.find_elements_by_css_selector('input[type=checkbox]').pop().click() time.sleep(1) dr.quit()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM