简体   繁体   English

如何通过 aria-hidden 读取跨度?

[英]How to read span through aria-hidden?

I've been trying for about 2 hours now with no luck to see how to read text between a span that has an "aria-hidden=true" tag.我已经尝试了大约 2 个小时,但没有看到如何在具有“aria-hidden=true”标签的跨度之间读取文本。 The code for the site is like this:该网站的代码是这样的:

<div class="badge">
    <span aria-hidden="true">123</span>
</div>

Any idea how you can view the text with xpath or anything similar?知道如何使用 xpath 或类似的东西查看文本吗? My current code is this, but returns random span text from across the page for some reason.我当前的代码是这样的,但由于某种原因从整个页面返回随机跨度文本。

for i in web.find_elements(xpath="//div[contains(concat(' ', @class, ' '), ' badge ')]//span[1]"):
                    print(i.get_attribute("innerText"))

Any help would be greatly appreciated任何帮助将不胜感激

Based on the HTML you posted, I don't see the attribute innerText in the span element.根据您发布的 HTML,我在span元素中看不到属性innerText To get the text of the element in Selenium, you should use getText()要获取 Selenium 中元素的文本,您应该使用getText()

for i in web.find_elements(xpath="//div[contains(concat(' ', @class, ' '), ' badge ')]//span[1]"):
                    print(i.getText())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM