【问题标题】:how to find id by class name python selenium如何通过类名 python selenium 查找 id
【发布时间】:2019-03-11 05:18:52
【问题描述】:
<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)打开时都会随机变化。我想通过class="select_step ON 或任何其他替代方式找到随机生成的"id"

【问题讨论】:

  • 我建议您通过选择答案旁边的灰色勾号来学习如何接受和回答。用户需要时间来回答问题,我们至少可以用信誉积分奖励他们。

标签: python selenium


【解决方案1】:

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

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

然后获取id属性:

print(input_tag.get_attribute('id'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 2019-08-16
    • 2020-04-25
    相关资源
    最近更新 更多