zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    docker的安装
    Linux的常用命令
    HTTP协议,HTTPS协议,Websocket协议
    常用排序
    go的数组,切片,map
    if-else,switch,for循环
    go的函数,包以及mode的补充
    Android学习笔记——从源码看Handler的处理机制
    ElementUI
    关于IO的理解
  • 原文地址:https://www.cnblogs.com/forcepush/p/6645929.html
Copyright © 2011-2022 走看看