无法使用 Python selenium 单击按钮,出现错误 ElementNotInteractableException

Not being able to click on a button using Python selenium with error ElementNotInteractableException

我正在使用 Python Selenium 打开 https://www.walmart.com/ and then want to click "Create an account" tab under "Sign In Account" as shown in this Walmart website pic。 Walmart官网按钮源码及图片如下:

<a link-identifier="Create an account" class="no-underline" href="/account/signup?vid=oaoh">
<button class="w_C8 w_DB w_DE db mb3 w-100" type="button" tabindex="-1">Create an account</button>
</a>

Walmart Website Source code-Pic

我的 python 打开 https://www.walmart.com/ 访问 创建帐户 按钮的代码是如下:

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

url = "https://www.walmart.com/"

s=Service('C:/Users/Samiullah/.wdm/drivers/chromedriver/win32/96.0.4664.45/chromedriver.exe')
driver = webdriver.Chrome(service=s)
driver.get(url)
driver.maximize_window()

elems = driver.find_element(By.XPATH, '//button[normalize-space()="Create an account"]')
time.sleep(3)
elems.click()

但是,我收到了 ElementNotInteractableException 错误,如此 Error Pic 所示。

任何人都可以指导我我的 code/approach 有什么问题吗?

提前致谢

您不能直接点击该元素,您必须将鼠标悬停在“登录”元素上才能显示该元素。
也强烈建议使用预期条件。
这应该有效:

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
url = "https://www.walmart.com/"

s=Service('C:/Users/Samiullah/.wdm/drivers/chromedriver/win32/96.0.4664.45/chromedriver.exe')
driver = webdriver.Chrome(service=s)
wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)
driver.get(url)
driver.maximize_window()
sign_in_btn = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[text()='Sign In']")))
actions.move_to_element(sign_in_btn).perform()
time.sleep(0.5)
wait.until(EC.visibility_of_element_located((By.XPATH, '//button[normalize-space()="Create an account"]'))).click()