Selenium3+webdriver学习笔记3(xpath方式元素定位)
#!/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"
url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/a03.html"
driver=webdriver.Firefox() driver.get(url) #id name class 属性定位
driver.find_element_by_xpath("//*[@id='kw']").send_keys(keys)
driver.find_element_by_xpath("//*[@name='wd']").send_keys(keys)
driver.find_element_by_xpath("//*[@class='s_ipt']").send_keys(keys) #其他属性定位
driver.find_element_by_xpath("//*[@autocomplete='off']").send_keys(keys) #指定标签名称 写标签名称,不指定则写 *,如搜索框 input
driver.find_element_by_xpath("//input[@class='s_ipt']").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"> driver.find_element_by_xpath("//form[@id='form']/span/input").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> driver.find_element_by_xpath("//option[@value='2']").click() # <a href="https://www.hao123.com" target="_blank" class="mnav">hao123</a>
# 模糊匹配
driver.find_element_by_xpath("//*[contains(text(),'hao123')]").click() # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#模糊匹配 包含属性
driver.find_element_by_xpath("//*[contains(@id,'kw')]").send_keys(keys) #模糊匹配 已什么开头
driver.find_element_by_xpath("//input[starts-with(@class,'s_')]").send_keys(keys) # find_element方式 单个数据
driver.find_element(by='id',value='kw').send_keys(keys) # a03.html文件
# <div id="u_sp" class="s-isindex-wrap s-sp-menu">
# <a href="http://news.baidu.com" target="_blank" class="mnav">新闻</a>
# <a href="https://www.hao123.com" target="_blank" class="mnav">hao123</a>
# <a href="http://map.baidu.com" target="_blank" class="mnav">地图</a>
# <a href="http://v.baidu.com" target="_blank" class="mnav">视频</a>
# <a href="http://tieba.baidu.com" target="_blank" class="mnav">贴吧</a>
# <a href="http://xueshu.baidu.com" target="_blank" class="mnav">学术</a>
# <a id="s_username_top" class="s-user-name-top" data-tid="2004" href="http://i.baidu.com/" target="_blank"></a></div> #find_elements方式 多个数据
len1=driver.find_elements_by_xpath("//a[@class='mnav']")
len2=driver.find_elements(by='class name',value='mnav')
print(len(len1))
print(len(len2)) time.sleep(3)
driver.quit()
Selenium3+webdriver学习笔记3(xpath方式元素定位)的更多相关文章
- 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学习笔记4(css方式元素定位)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...
随机推荐
- 安装pillow
最近想学Python的图像操作.首要任务就是安装pillow.这个强大的图形处理工具. 但是我遇到了一个问题. Collecting pilow Could not find a version t ...
- tcp_fast_open的概念 作用以及实现(转)
引言 三次握手的过程中,当用户首次访问server时,发送syn包,server根据用户IP生成cookie,并与syn+ack一同发回client:client再次访问server时,在syn包携带 ...
- 文件解析库doctotext源码分析
doctotext中没有make install选项,make后生成可执行文件 在buile目录下面有.so动态库和头文件,需要的可以从这里面拷贝 build/doctotext就是可执行程序. ...
- 函数PARSENAME使用和截取字符串
MS SQL server有一个函数PARSENAME ( 'object_name' , object_piece ). 函数有2个参数: Object_name 检索的对象名称.即是:服务器名.数 ...
- Keras AttributeError 'NoneType' object has no attribute '_inbound_nodes'
问题说明: 首先呢,报这个错误的代码是这行代码: model = Model(inputs=input, outputs=output) 报错: AttributeError 'NoneType' o ...
- ue4 代码入门
官网:暴露游戏元素给蓝图 https://docs.unrealengine.com/latest/CHN/Engine/Blueprints/TechnicalGuide/ExtendingBlue ...
- 渲染路径-Unity5 的新旧推迟渲染Deferred Lighting Rendering Path
Unity5 的新旧延迟渲染Deferred Lighting Rendering Path unity5 的render path ,比4的区别就是使用的新的deferred rendering,之 ...
- [NOIP2012] 摆花
1270. [NOIP2012] 摆花 http://cogs.pro/cogs/problem/problem.php?pid=1270 ★ 输入文件:flower.in 输出文件:flow ...
- 洛谷P3172 [CQOI2015]选数(容斥)
传送门 首先,进行如下处理 如果$L$是$K$的倍数,那么让它变成$\frac{L}{K}$,否则变成$\frac{L}{K}+1$ 把$H$变成$\frac{H}{K}$ 那么,现在的问题就变成了在 ...
- Whatweb网站指纹信息收集工具
常规扫描:whatweb www.baidu.com 批量扫描: whatweb -i /root/12.txt 详细回显扫描:whatweb -v www.baidu.com 加强扫描强度:what ...