#!/usr/bin/env python
# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#id
keys="selenium自动化"
url="https://www.baidu.com/"
# url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/select01.html"
driver=webdriver.Firefox() driver.get(url) #id class 属性定位 #表示id .表示class 使用标签属性,表示为标签名
driver.find_element_by_css_selector("#kw").send_keys(keys) driver.find_element_by_css_selector(".s_ipt").send_keys(keys) #name属性定位
driver.find_element_by_css_selector("[name='wd']").send_keys(keys) #其他属性定位
driver.find_element_by_css_selector("[autocomplete='off']").send_keys(keys) # 标签与属性的组合来定位 id name class 其他属性
driver.find_element_by_css_selector("input#kw").send_keys(keys) driver.find_element_by_css_selector("input[name='wd']").send_keys(keys) driver.find_element_by_css_selector("input.s_ipt").send_keys(keys) driver.find_element_by_css_selector("input[autocomplete='off']").send_keys(keys) # <form name="f" id="form" action="/s" class="fm" onsubmit="javascript:F.call('ps/sug','pssubmit');">
# <span id="s_kw_wrap" class="bg s_ipt_wr quickdelete-wrap">
# <span class="soutu-btn"></span><input type="text" class="s_ipt" name="wd" id="kw" maxlength="100" autocomplete="off"> #用>表示层级关系 id name class
driver.find_element_by_css_selector("form#form>span>input").send_keys(keys)
driver.find_element_by_css_selector("form[name='f']>span>input").send_keys(keys)
driver.find_element_by_css_selector("form.fm>span>input").send_keys(keys) #多属性组合
driver.find_element_by_css_selector("input[id='kw'][name='wd']").send_keys(keys) #select01.html文件
# 下拉框选择形式
# <select id="status" class="form-control valid" onchange="" name="status">
# <option value=""></option>
# <option value="0">未审核</option>
# <option value="1">初审通过</option>
# <option value="2">复审通过</option>
# <option value="3">审核不通过</option>
# </select> # 定位子元素 nth-child(n)
driver.find_element_by_css_selector("select#status>option:nth-child(4)").click() time.sleep(3)
driver.quit()

Selenium3+webdriver学习笔记4(css方式元素定位)的更多相关文章

  1. Selenium3+webdriver学习笔记2(常用元素定位方式,定位单个元素共8种,总共有23种)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...

  2. Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...

  3. Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )

    !/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...

  4. Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...

  5. Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...

  6. Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...

  7. Python3+Selenium3+webdriver学习笔记11(cookie处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...

  8. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  9. Selenium3+webdriver学习笔记3(xpath方式元素定位)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...

随机推荐

  1. 快速排序(java)

    快速排序是冒泡排序的优化,是一种非常高效的排序, 甚至是目前为止最高效的排序,其思想是这样的:设数组a中存放了n个数据元素,low为数组的低端下标,high为数组的高端下标,从数组a中任取一个元素(通 ...

  2. C# 把datagridview控件上的表格输出到excel文件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. PCL类的设计结构

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=243 类和应用程序接口 对于PCL的大多数类而言,调用接口(所有public ...

  4. centos6.5安装sublime Text3破解版

    安装后的效果图: 在csdn上找到了一个破解版. http://download.csdn.net/download/phpscott2/5356561 安装后,能够运行,但每次打开都提示没有安装py ...

  5. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  6. iOS 防止抓包

    原文链接:https://www.jianshu.com/p/1ab83d726d3f 现在 APP 开发,数据的保密性越来越受重视,保密性高才不会让数据轻易被泄露,同时保护到用户和公司的利益.如何做 ...

  7. ubuntu18.04安装配置opencv3.4.0

    1.安装配置相关工具及依赖库 sudo apt-get install build-essential # 必须的,gcc编译环境 sudo apt-get install cmake git lib ...

  8. Codeforces617E【莫队算法+前缀异或】

    题意: 给出一系列数,对每个查询区间,计算有多少个子区间异或为k. 思路: 可以先预处理异或前缀,一个区间[L,R]的异或值=sum[R]^sum[L-1]; 如果当前区间是[a,b],加一个右端点b ...

  9. 51nod1105(二分)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1105 题意:中文题诶- 思路:直接二分答案,再通过二分找有多少 ...

  10. 洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon

    P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W ( ...