【问题标题】:Selenium Python - Finding Elements by Class Name With dynamic parametersSelenium python - 通过带有动态参数的类名找到元素
【发布时间】:2021-11-19 10:59:33
【问题描述】:

我想知道如果类名有静态paramdynamic param,是否有任何方法可以按类名查找元素,我将解释: 我得到了

< class="**dataset-selection-dialog-actions** *ng-tns-c139-19*" >

'dataset-selection-dialog-actions' 是静态的,但 'ng-tns-c139-19' 可以更改任何重新加载页面。

我可以在没有动态 param 的情况下找到这个元素吗?

谢谢。

【问题讨论】:

    标签: python selenium selenium-webdriver css-selectors


    【解决方案1】:

    是的,为什么不呢。

    请使用find_element_by_class_name('dataset-selection-dialog-actions')

    但要确保它是 HTMLDOM 中的唯一元素。

    要检查它是否唯一,请使用这个 css 选择器,.dataset-selection-dialog-actions

    PS:如果我们在HTML DOM 中有唯一条目,请检查dev tools(谷歌浏览器)。

    检查步骤:

    Press F12 in Chrome -> 转到element 部分 -> 做一个CTRL + F -> 然后粘贴css selector .dataset-selection-dialog-actions 看看,如果你想要的element 得到突出显示1/1 匹配节点。

    【讨论】:

      猜你喜欢
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      相关资源
      最近更新 更多