通过selenium python中的文本与HTML元素进行交互

发布于 2025-02-08 17:02:40 字数 803 浏览 2 评论 0原文

我需要与HTML元素进行ID互动,例如

<span class="a-button-inner">
    <input name="submit.addToCart" aria-label="Aggiungi al carrello dal venditore VERONCART SRL con prezzo 775,00&nbsp;€
" aria-labelledby="" class="a-button-input" type="submit">
<span id="a-autoid-2-offer-1-announce" class="a-button-text" aria-hidden="true"> Aggiungi al carrello </span>
</span>

我在网站上有许多此类按钮,并且我必须通过ARIA标签中的数值文本识别它们,在这种情况下为775.i

wd.find_element_by_xpath('//*[contains(text()='775')]')

他们一起

wd.find_element_by_css_selector('//input[value*='775']')

工作。我已经陷入困境了几天,我很感激我可以帮助我。

I need to interact with an HTML element with an id such as

<span class="a-button-inner">
    <input name="submit.addToCart" aria-label="Aggiungi al carrello dal venditore VERONCART SRL con prezzo 775,00 €
" aria-labelledby="" class="a-button-input" type="submit">
<span id="a-autoid-2-offer-1-announce" class="a-button-text" aria-hidden="true"> Aggiungi al carrello </span>
</span>

I have many of this buttons on the site and I must identify them by the numerical text inside the aria label,in this case 775.I have tried
with

wd.find_element_by_xpath('//*[contains(text()='775')]')

and

wd.find_element_by_css_selector('//input[value*='775']')

None of them works. I've been stuck on this for days, I'd be grateful I someone could help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我乃一代侩神 2025-02-15 17:02:40

您离解决方案不远。要指定我们要在哪个属性进行搜索的搜索中的选择器,而不是使用text()表示输入的文本,我们使用属性名称,即@ ARIA-LABEL

wd.find_element_by_xpath("//input[contains(@aria-label, '775')]")

请注意,不要将775排除到我们的XPath。

You are not far from the solution. To specify the selector in which attribute we want to do the search of the value, instead of using text() which mean the text of the input, we use the attribute name, which is @aria-label.

wd.find_element_by_xpath("//input[contains(@aria-label, '775')]")

Please note to not excluding the 775 to our XPath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文