python - 如何通过类名 python selenium 查找 id
问题描述
<input class="select_step ON " id="step_9285985_select" name="step_9285985_select" type="checkbox" value="9285985">
我正在通过 python selenium 自动化我们项目的常规任务。一步构建,请帮助我。
根据上面的 html 代码id="step_9285985_select"
,每次浏览器通过webdriver
(python Selenium)打开时都会随机变化。我想找到"id"
由 theclass="select_step ON
或任何其他替代方案随机生成的。
解决方案
首先通过 CSS 选择器找到元素:
input_tag = driver.find_element_by_css_selector('input.select_step.ON')
然后获取id
属性:
print(input_tag.get_attribute('id'))
推荐阅读
- python - 这是否可以从 Django(Python) Web 应用程序调用 QGroundControl 的方法?
- discord.js - MessageEmbed 中的“客户端”存在问题
- cuda - CUDA 统一内存和设备代码中 std::vector 的使用
- swift - 在 UITable 中加载数据时出现问题 - 仅在第二次单击后刷新数据
- ruby-on-rails - facebook auth 自我召回后的sign_in_and_redirect
- python - 如何使用 Python 3 正确操作内存中的 tar 文件?
- c - C++ Libcurl + Cloudflare
- javascript - 在网页上,如果用户根本没有点击过任何页面元素,那么 body 元素是否首先获得任何键盘事件?
- javascript - 尝试添加到我的传单地图时出错,它是 LayerGroup
- go - Goroutines:在哪里关闭