我正在尝试在nike网上商店中结帐,但我已经尝试了所有方法并进行了搜索,但找不到答案。
https://www.nike.com/nl/nl/checkout/tunnel
我有:
driver.find_element_by_xpath('//button[@id="qa-guest-checkout-mobile"]').click()
<button id="qa-guest-checkout-mobile" aria-label="Guest Checkout"
class="ncss-btn-accent u-rounded u-full-width ncss-brand u-uppercase pt3-sm pt2-lg pr5-sm pb3-sm pb2-lg pl5-sm fs14-sm d-lg-h">
<span class="d-sm-ib va-sm-m mr1-sm">Afrekenen als bezoeker</span></button>
我尝试使用id,css等查找,但它不起作用。我在这里做错了什么?当我打印元素时,我只会得到1个元素,然后不会出现错误。
File "C:\Users\X\OneDrive\Desktop\SN\NA.py", line 23, in <module>
test = driver.find_element_by_xpath('//button[@id="qa-guest-checkout-mobile"]').click()
File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)
答案 0 :(得分:2)
经过大量搜索,我发现this post与this answer并能够编写以下代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome()
browser.get('https://www.nike.com/nl/nl/checkout/tunnel')
element = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, "//div/button[@id='qa-guest-checkout-mobile']")))
browser.execute_script("arguments[0].click();", element)
成功单击该按钮。由于某些原因,您必须使用javascript ...强制点击按钮。