如何查找锚标签<a>按属性名称和/或值? [英] How lookup anchor tag <a> by attribute name and/or value?
本文介绍了如何查找锚标签<a>按属性名称和/或值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我试图自动化的网络:
This is the web that I am trying to automate:
我的要求是根据输入的颜色点击图像.例如,如果输入红色"作为输入,我必须像上一张图片一样点击红色运动衫.
My requirement is to click on the image depending on the color entered as input. For example, if "red" is entered as input I must click in the red sweatshirt like the previous picture.
<ul class="styles">
<li><a class="" data-images="..." data-style-name="Red" data-style-id="22898" href="...">
<img src="//assets.supremenewyork.com/168724/sw/RymAY-fhCvA.jpg" alt="Rymay fhcva" width="32" height="32"></a>
</li>
<li><a class="" data-images="..." data-style-name="Natural" data-style-id="22899" href="...">
<img src="//assets.supremenewyork.com/168722/sw/P9adXZbmQQ4.jpg" alt="P9adxzbmqq4" width="32" height="32"></a>
</li>
<li><a class="" data-images="..." data-style-name="Navy" data-style-id="22900" href="...">
<img src="//assets.supremenewyork.com/168723/sw/nC1YwBFpU5g.jpg" alt="Nc1ywbfpu5g" width="32" height="32"></a>
</li>
<li><a class="" data-images="..." data-style-name="Black" data-style-id="22901" href="...">
<img src="//assets.supremenewyork.com/168721/sw/viAmPE40S9U.jpg" alt="Viampe40s9u" width="32" height="32"></a>
</li>
</ul>
在 data-style-name="Red" 属性中.
我试过这个:
driver.find_element_by_xpath('//a[@itemprop="model">{}</p>]'.format(color.get()))
但是好像没有找到.
我怎样才能做到这一点?
How can I achieve this?
谢谢
推荐答案
使用以下 XPath :
XPATH ://p[@class='styleprotect' and normalize-space()='"+COLOR_VALUE_VARIABLE+"']
XPATH : //p[@class='style protect' and normalize-space()='"+COLOR_VALUE_VARIABLE+"']
driver.find_element_by_xpath("//p[@class='style protect' and normalize-space()='"+COLOR_VALUE_VARIABLE+"']")
这篇关于如何查找锚标签<a>按属性名称和/或值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文