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