首页 > 解决方案 > 如何通过类名 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或任何其他替代方案随机生成的。

标签: pythonselenium

解决方案


首先通过 CSS 选择器找到元素:

input_tag = driver.find_element_by_css_selector('input.select_step.ON')

然后获取id属性:

print(input_tag.get_attribute('id'))

推荐阅读