我试图单击产品页面中的某个项目以将某些内容添加到我的购物车,但我无法执行此操作,因为我收到许多错误或没有任何反应。 这是我的代码:
i = driver.find_element_by_xpath("//button[@class='exclusive']")
i.click
这是网页代码:
<p id="add_to_cart" class="buttons_bottom_block no-print">
<button type="submit" name="Submit" class="exclusive">
<span>Add to cart</span>
</button>
</p>
抱歉,如果我犯了错误,但我是新人!感谢您的帮助。
最佳答案
要单击产品页面中的商品以添加到购物车,您可以使用以下任意一项 Locator Strategies :
使用
css_selector
:driver.find_element_by_css_selector("p.buttons_bottom_block.no-print>button.exclusive[name='Submit']>span").click()
使用
xpath
:driver.find_element_by_xpath("//p[@class='buttons_bottom_block no-print']/button[@class='exclusive']/span[text()='Add to cart']").click()
关于python - 如何通过 Selenium 和 Python 点击某个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54967544/