【发布时间】:2023-03-23 18:45:01
【问题描述】:
我正在尝试使用 Selenium Python 添加到购物车。当我运行代码时,网站显示添加到购物车,然后出现错误。当我进入购物车页面时,它只是说没有物品添加到购物车中。我在这里做错了吗?
我的代码如下:
#add to cart
driver.find_element_by_xpath('//form[@action="/cart/add"]/input[@class="add cart-btn clearfix"]').click()
HTML如下:
<div class="product-form-wrapper">
<form action="/cart/add" method="post" data-money-format="£{{amount}}" id="product-form-4424062369869" class="product-form" >
<div id="product-variants" class="">
<div class="select-wrapper">
<select id="product-select" name="id" class="">
<option value="31655905919053">Medium</option>
<option value="31655906017357">Large</option>
<option value="31655906148429">X-Large</option>
</select>
</div>
</div>
<input type="submit" name="button" class="add cart-btn clearfix" data-text="Add to Cart" value="Add to Cart" />
【问题讨论】:
-
请包含错误和完整的 html 或指向它的链接
-
在加入购物车之前可能必须选择尺码?
-
正如@Farhad 提到的,在添加到购物车之前可能存在选择尺寸的情况......所以,我建议您在点击添加到购物车之前和之后使用一些屏幕截图来跟踪该过程点击添加到购物车。这是 CMD:driver.save_screenshot('/path-to-save-the-screenshot')。
标签: python-2.7 selenium selenium-webdriver