如何解决找不到Selenium Python元素
这是我要剪贴的HTML链接 https://pk.khaadi.com/unstitched/r20206-red-r20206-red-pk.html
<div class="swatch-attribute-options clearfix">
<div class="swatch-option color selected" option-type="1" option-
id="61" option-label="RED" option-tooltip-thumb="" option-tooltip-
value="#ee0000" "="" style="background: #ee0000 no-repeat center;
background-size: initial;">
</div>
<div class="swatch-option color selected" option-type="1" option-
id="73" option-label="YELLOW" option-tooltip-thumb="" option-tooltip-
value="#feed00" "="" style="background: #feed00 no-repeat center;
background-size: initial;">
</div>
</div>
Color = S_Driver.find_elements_by_xpath( '//*[@id="product-options-wrapper"]/div/div/div[1]/div' )
Xpath位于外部div,其中两个颜色div都存在
for c in Color:
n_Color.append(c.get_attribute( 'option-label' ))
print( n_Color + '\n' )
这就是我尝试通过'option-label'属性提取颜色的方式
解决方法
使用以下方法更改xpath:
//div[@class='swatch-option color']
基于提供的屏幕截图创建,希望基于此页面没有其他匹配项。如果是这样,请使用:
//div[@class='swatch-option color' and @option-type='1']
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。