通过selenium python中的文本与HTML元素进行交互
我需要与HTML元素进行ID互动,例如
<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>
我在网站上有许多此类按钮,并且我必须通过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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您离解决方案不远。要指定我们要在哪个属性进行搜索的搜索中的选择器,而不是使用
text()
表示输入的文本,我们使用属性名称,即@ ARIA-LABEL
。请注意,不要将
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
.Please note to not excluding the
775
to our XPath.