python - Selenium 使用 OR/AND 运算符选择特定内容 - python
问题描述
我正在使用 Python 解决 Selenium 中的一个问题。
这是我所拥有的虚拟草稿。
<body>
<button info="content1" aria-label="1">"Click 1"</button>
<button info="content1" aria-label="2">"Click 2"</button>
<button info="content2" aria-label="2">"Click 2"</button>
<button info="content2" aria-label="4">"Click 4"</button>
<body>
我的目标是选择具有info="content1"
和aria-label="2"
我已经试过了
element=driver.find_element_by_css_selector('button[info="content1"] and button[aria-label="2"]')
但不起作用并返回 NoSuchElementException
你能帮帮我吗?
解决方案
只需将两个带括号的属性选择器放在一起,没有 no and
:
element = driver.find_element_by_css_selector('button[info="content1"][aria-label="2"]')
推荐阅读
- mongodb - 每 x 秒/分钟发送和接收重复信息的架构
- c# - 使用httpclient C#模拟两次点击并通过PKI证书
- omnet++ - 如何在 OMNeT++ IDE 中禁用引号和括号的自动完成
- angular - 使用 Angular 项从字符串创建动态 CSS 样式
- c# - Button Resize 中的图像分辨率问题
- react-native - 如何在网格中拖放图像以调整它们在本机反应中的位置
- r - R Shiny Markdown 表在应用程序与预览中看起来不一样
- node.js - Cors Access-Control-Allow-Credentials 失败时表示它未设置为 true。想法?
- python - Pandas 通过多列和键排序
- flutter - 如何将提供者类名作为参数传递?