xpath定位不包含某种属性的元素

今天定位一个页面中的input文本框,发现竟然有两个几乎一模一样的html代码的input文本框。

唯一不同的是,一图中的input有一个comps="[object Object],[object Object]"的属性和属性值,二图则没有。我要定位的是二图中的input,并且输入内容。

代码如下:

复制代码
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import random


phone_input = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="mobilePhone" and not(@comps)]')))
time.sleep(random.randint(1, 3))        # 随机等待一到三秒
phone_input.send_keys("6466589337")
time.sleep(2)

not(@comps)即代表定位不包含叫做comps属性的元素。

还可以用and或者or来指定多个属性值。

复制代码
//tr[not(@id) and not(@class)]
或者
//tr[not(@id) or not(@class)]
相关推荐
C_心欲无痕1 天前
vue3 - 响应式数ref与reactive的深度解析
前端·javascript·vue.js
全栈老石1 天前
TypeScript 中 Type 和 Interface 傻傻分不清?看完这篇就不纠结了
前端·typescript
沈千秋.1 天前
xss.pwnfunction.com闯关(1~6)
java·前端·xss
于谦1 天前
✨ feat(app1,pkg1): monorepo生成规范化提交信息的最优解 - committier
javascript·github·代码规范
浪浪山_大橙子1 天前
吃透 CSS 常用函数:从布局到美化,18 个高频函数让样式写得又快又优雅
前端
我是ed.1 天前
Vue3 图片标注插件 AILabel
前端·vue3·标注·ailabel
晚星star1 天前
《深入浅出 Node.js》第四章:异步编程 详细总结
前端·node.js
无心使然1 天前
vant实现自定义日期时间选择器(年月日时分秒)
前端·vue.js