【问题标题】:Is it possible to locate element by partial class match in Selenium是否可以通过 Selenium 中的部分类匹配来定位元素
【发布时间】:2022-01-07 10:35:44
【问题描述】:

我开始使用 Selenium,我试图在 cnn 网站上找到“下一步”按钮,如果它不是点击它的最后一页,则结束程序。

启用按钮的html代码是:

<div class="pagination-arrow pagination-arrow-right cnnSearchPageLink text-active">
    "Next"
 <i class="icon icon--arrow-right"></i>
</div>

禁用按钮的html代码是:

<div class="pagination-arrow pagination-arrow-right text-deactive">
    "Next"
 <i class="icon icon--arrow-right"></i>
</div>

应该如何解决?我尝试is_enabled() 或在类名中查找部分文本但没有成功。我该怎么办?

【问题讨论】:

    标签: python selenium selenium-webdriver web-scraping


    【解决方案1】:

    你可以使用

    div.text-active
    

    CSS 选择器代表您共享的第一个 HTML div。

    div.text-deactive
    

    表示第二个 HTML div 的 CSS 选择器

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

    检查步骤:

    Press F12 in Chrome -> 转到element 部分 -> 做一个CTRL + F -> 然后粘贴css selector 看看,如果你想要的element 用@ 得到高亮 987654330@匹配节点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      • 2016-07-05
      相关资源
      最近更新 更多