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()
  • 相关阅读:
    接口报错mixed content blocked
    重拾单片机
    部署ajax服务-支持jsonp
    linkageSystem--串口通信、socket.io
    node安装问题
    jshint之对!的检验
    node之websocket
    调试node服务器-过程
    oracle取某字符串字段的后4位
    vmware 共享文件夹
  • 原文地址:https://www.cnblogs.com/forcepush/p/6645929.html
Copyright © 2011-2022 走看看