Selenium3+webdriver学习笔记4(css方式元素定位)
#!/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方式元素定位)的更多相关文章
- Selenium3+webdriver学习笔记2(常用元素定位方式,定位单个元素共8种,总共有23种)
		
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...
 - Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)
		
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...
 - Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )
		
!/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...
 - Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)
		
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...
 - Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)
		
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...
 - Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)
		
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...
 - Python3+Selenium3+webdriver学习笔记11(cookie处理)
		
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...
 - Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
		
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...
 - Selenium3+webdriver学习笔记3(xpath方式元素定位)
		
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...
 
随机推荐
- web.xml中的<jsp-config>的用法详解
			
<jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素. 其中<taglib>元素在JSP 1.2时就已 ...
 - deprecated conversion from string constant to ‘char*’
			
deprecated conversion from string constant to ‘char*’ #include <iostream> using namespace std; ...
 - MVN 命令行
			
Maven依赖查询: http://mvnrepository.com/ Maven常用命令: 1. 创建Maven的普通java项目: mvn archetype:create - ...
 - 10. windows下原来可以这样隐藏webshell
			
1.利用保留字隐藏 windows系统有些保留文件夹名,windows系统不允许用这些名字命名文件夹,如 aux|prn|con|nul|com1|com2|com3|com4|com5|com6|c ...
 - 2018ACM-ICPC宁夏邀请赛 A-Maximum Element In A Stack(栈内最大值)
			
Maximum Element In A Stack 20.91% 10000ms 262144K As an ACM-ICPC newbie, Aishah is learning data s ...
 - Parallel类
			
Parallel类是对线程很好的一个抽象.该类位于System.Threading.Tasks名称空间中,提供了数据和任务并行性. Parallel类定义了并行的for和foreach的静态方法.Pa ...
 - Kth Largest Element in a Stream
			
Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...
 - qsc54(区间dp)
			
题目链接:http://qscoj.cn/problem/54/ 题意:中文题诶- 思路:区间dp 我们可以用dp[i][j]存储区间[i, j]最少需要的打印次数,若没有相同的字母,那么需要的打印次 ...
 - uoj#311. 【UNR #2】积劳成疾(期望dp)
			
传送门 果然\(dp\)题就没咱啥事儿了 设\(f_{i,j}\)为长度为\(i\)的区间,所有元素的值不超过\(j\)的总的疲劳值 如果\(j\)没有出现过,那么\(f_{i,j}=f_{i,j-1 ...
 - 剑指Offer的学习笔记(C#篇)-- 数字在排序数组中出现的次数
			
题目描述 统计一个数字在排序数组中出现的次数. 一 . 题目分析 该题目并不是难题,但该题目考察目的是正确的选择合适的查找方法.题目中有一个关键词是:排序数组,也就是说,该数组已经排好了,我一开始直接 ...