#!/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. AAAAAA

    有可能被立案调查.暂停上市.退市风险警示*ST.特别处理ST的公司:银鸽投资(SH:600069).天山生物(SZ:300313).金贵银业(SZ:002716).美盛文化(SZ:002699).未名 ...

  2. mysql create table

  3. Robot Framework基础学习(六)

    网页弹窗 参考:http://blog.csdn.net/Allan_shore_ma/article/details/65629246 常见的网页弹窗,有如下几类: alert ajax ifram ...

  4. Codeforces 489A SwapSort (水题)

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  5. layer常用方法

    弹出层layer的使用 弹出层layer的使用 Intro layer是一款web弹层组件,致力于服务各个水平段的开发人员.layer官网:http://layer.layui.com/ layer侧 ...

  6. 防止APP退到被安卓系统清理

    一个是尽量提高APP权限,无非就是保持APP始终界面在前台 二是使用守护进程方法,被清理了立刻自己启动, 三是前台跟后台进程分开,被重启了恢复原始环境. // 申请设备电源锁,在服务start的时候. ...

  7. 模拟一则ORA-600 [4194][][]故障并处理

    环境:OEL 5.7 + Oracle 11.2.0.3 1.模拟ORA-600 [4194][][]故障 2.使用bbed处理 3.尝试启动数据库 1.模拟ORA-600 [4194][][]故障 ...

  8. NLP入门(十)使用LSTM进行文本情感分析

    情感分析简介   文本情感分析(Sentiment Analysis)是自然语言处理(NLP)方法中常见的应用,也是一个有趣的基本任务,尤其是以提炼文本情绪内容为目的的分类.它是对带有情感色彩的主观性 ...

  9. 3dmax切割平行线

    1 选择物体(可编辑多边形),选择边 ,然后点击切片平面 2 然后会出现黄色线框 3 移动旋转黄色线框到合适位置,然后点切片 4 结果

  10. 洛谷P5173 传球(暴力)

    传送门 真·暴力艹过去 不难发现这个转移其实就是一个循环卷积的形式,设有多项式\(A=x+x^{n-1}\),那么\(f_m=f_0\times A^m\) 直接暴力计算并卡常就行了 //minamo ...