我正在使用 Python 上的 Selenium 在 WellGosh.com 上编写“添加到购物车”功能。
我有代码获得正确的尺寸以添加到购物车并登录我的帐户并到达正确的送货地址,但是当我尝试确认送货方式(联邦快递)时,它不会让我点击继续按钮。
以下是结帐代码的示例:
def Checkout():
#brings you to your cart
driver.get('https://wellgosh.com/checkout/cart')
#clicks to checkout
checkout=driver.find_element_by_xpath('//*[@id="shopping-cart-table"]/tfoot/tr/td/div[2]/a')
checkout.click()
#Log in
login=driver.find_element_by_xpath('//*[@id="login-email"]')
login.send_keys(e_mail)
password=driver.find_element_by_xpath('//*[@id="login-password"]')
password.send_keys(Pass)
LogIn=driver.find_element_by_xpath('//*[@id="checkout-step-login"]/div/div[2]/div/button')
LogIn.click()
cont=driver.find_element_by_xpath('//*[@id="billing-buttons-container"]/button')
cont.click()
driver.implicitly_wait(100)
element = driver.find_element_by_xpath('//*[@id="shipping-method-buttons-container"]/button')
element.click()
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见
这是 HTML 代码的片段:
</script>
</div>
<div class="buttons-set" id="shipping-method-buttons-container">
<p class="back-link"><a href="#" onclick="checkout.back(); return false;"><i class="fa fa-chevron-left plain"></i>Back</a></p>
<button type="button" class="button btn-continue" onclick="shippingMethod.save()">Continue</button>
<span id="shipping-method-please-wait" class="please-wait zoooooom" style="display:none;">
<i class="fa fa-cog fa-spin plain"></i>
</span>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
小智 -2
如果您在单击按钮时遇到问题,为什么不运行该按钮的“onclick”属性中的 JavaScript?例如,在 HTML 代码段中,您可以执行以下操作,而不是查找元素并单击它:
driver.execute_script("shippingMethod.save()")
请注意,如果此页面使用 iFrame,则必须将驱动程序切换到适当的 iFrame,然后才能找到/选择其中的子元素。
| 归档时间: |
|
| 查看次数: |
976 次 |
| 最近记录: |