selenium定位元素位置-xpath
xpath定位元素位置:
1、定位父兄节点:
<div>
<span>我是span1标签</span>
<a id="1" href="www.baidu.com">我是第1个a标签</a>
<p>我是p1标签</p>
<a id="2" href="www.baidu.com">我是第2个a标签</a>
<a id="3" href="www.baidu.com">我是第3个a标签</a>
<a id="4" href="www.baidu.com">我是第4个a标签</a>
<p>我是p2标签</p>
<span>我是span2标签</span>
<a id="5" href="www.baidu.com">我是第5个a标签</a>
</div> 获取第三个a标签的下一个a标签:"//a[@id='3']/following-sibling::a[1]"
获取第三个a标签后面的第N个标签:"//a[@id='3']/following-sibling::*[N]"
获取第三个a标签的上一个a标签:"//a[@id='3']/preceding-sibling::a[1]"
获取第三个a标签的前面的第N个标签:"//a[@id='3']/preceding-sibling::*[N]"
获取第三个a标签的父标签:"//a[@id='3']/.."
2、根据文本内容定位节点:
- browser.find_element_by_xpath('//button/span[contains(text(), "指定文本内容")]').click()
- browser.find_element_by_xpath("//[text()='文字内容']").click()
- browser.find_element_by_xpath("//*[contains(text(),'文字内容')]").click()
3、select标签操作:
from selenium.webdriver.support.select import Select
sel = driver.find_element_by_xpath("//select[@id='status']")
#根据value定位,option中需要有value属性
Select(sel).select_by_value('0') #未审核
Select(sel).select_by_value('1') #初审通过
Select(sel).select_by_value('2') #复审通过
Select(sel).select_by_value('3') #审核不通过
#根据位置index定位
Select(sel).select_by_index(0)
Select(sel).select_by_index(1)
selenium定位元素位置-xpath的更多相关文章
- Web自动化基础(一)使用Selenium定位元素
什么是元素?我们知道网页上有什么内容显示出来,比如一个按钮,一个输入框,一张图片,都可以理解成元素,这些元素是由html代码构成的,比如图片可以用<img>标签来展示,一个输入框可以用&l ...
- selenium 定位元素可以用多个findElement
selenium 定位元素可以用多个findElement,如driver.findElement(By.id"XXX").findElement(By.linkText(XXX) ...
- Selenium定位元素-Xpath的使用方法
工具 Xpath的练习建议下载火狐浏览器,下载插件Firebug.Firepath. 由于最新版火狐不支持Firebug等扩展工具了,所以需要下载49版以下的版本安装https://ftp.mozil ...
- Python+Selenium+Unittest框架使用——Selenium——定位元素(二)
1.定位元素(id.name.class.link.partial link) (1)find_element_by_id() 用百度定位测试,用firebug查看定位元素 ,输入框的id为“kw”, ...
- selenium定位元素方法汇总
#打开网页前三步 from selenium import webdriver driver=webidriver.Chrome() driver.get("https://www.baid ...
- selenium定位元素(本内容从https://my.oschina.net/flashsword/blog/147334处转载)
注明:本内容从https://my.oschina.net/flashsword/blog/147334处转载. 在使用selenium webdriver进行元素定位时,通常使用findElemen ...
- Python+Selenium定位元素的方法
Python+Selenium有以下八种定位元素的方法: 1. find_element_by_id() eg: find_element_by_id("kw") 2. find_ ...
- selenium 定位元素方法
1.通过id定位元素 写法1: element = driver.find_element_by_id("kw") 写法2: from selenium.webdriver.com ...
- Python Selenium定位元素常用解决办法
在做web应用的自动化测试时,定位元素是必不可少的,这个过程经常会碰到定位不到元素的情况(报selenium.common.exceptions.NoSuchElementException), ...
- python+selenium 定位元素的主要方法
selenium对web各元素的操作首先就要先定位元素,定位元素的方法主要有以下几种: 通过id定位元素:find_element_by_id("id_vaule") 通过name ...
随机推荐
- 【笔记】GTK的bind函数的参数
自打用了cinnamon之后 无比想念gnome的扩展 虽然都是基于gjs的东西 但是gnome的插件在cinnamon上没有就很痛苦 这次修改了个插件 recents 记录历史打开的文件 想添加个功 ...
- C# 两个list集合合并成一个,及升序降序
C# List集合合并 在开发过程中.数组和集合的处理是最让我们担心.一般会用for or foreach 来处理一些操作.这里介绍一些常用的集合跟数组的操作函数. 首先举例2个集合A,B. L ...
- strace 跟踪特定系统调用
/usrdsk/strace -tt -e trace=write -p 664 /usrdsk/strace -tt -e trace=%memory -p 664
- composer disgnoize public key fail
https://composer.github.io/pubkeys.html 还有这事, 太不可思议了哦.--怎么进去的, 真的不知道哦.
- 【Windows】IP 地址变为 169.254.x.x 的解决方法
最近每次开机 IP 地址都会自动跳至 169.254.x.x 段,连接不上网络,设置了固定 IP 也会跳段.因此找到以下解决方法: 『IP地址变成169.254.x.x 和固定ip两个IP地址的解决办 ...
- PowerShell学习笔记五_模块
PowserShell其他技巧 1. 执行完一个ps1文件后,不回收 有一个场景,在fun.ps1中,仅仅写了一段 Funtion fun([String] input) { } 然后打开PowerS ...
- Codeforces Round #766 (Div. 2) - D. Not Adding
GCD + 调和级数 Problem - 1627D - Codeforces 题意 有 \(n\;(1<=n<=10^6)\) 个互不相同的数 \(a[i]\;(1<=a[i]&l ...
- ORACLE 创建只读用户
create user cxuser01 identified by test123 default tablespace USERS temporary tablespace TEMP; --创建 ...
- python获取报文参考代码
# -*- coding:utf-8 -*- import sys import stomp import logging import time class MyListener(object): ...
- PHP连接FTP服务器获取文件
运行结果: