嗨,我正在尝试点击此链接上的“下一步”按钮: https://www.sneakql.com/en-GB/launch/culturekings/womens-air-jordan-1-high-og-court-purple-au/register
我试过了,但没用...
chrome.find_element_by_xpath('//*[@id="gatsby-focus-wrapper"]/main/div[2]/div[2]/div[2]/div/div/div[2]/div/form/div[3]/div/div/div/button').click();
我明白了:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-fullWidth" tabindex="0" type="submit">...</button> is not clickable at point (456, 870). Other element would receive the click: <div class="jss3" style="flex: 1 0 300px; margin: 15px;">...</div>
答案 0 :(得分:2)
“同意”按钮和“下一步”按钮具有相似的类名,因此“同意”按钮正在接收点击。
看看这是否有效:-
driver.find_element_by_xpath(".//button[contains(@class,'MuiButton-containedPrimary') and @type='submit']").click()
答案 1 :(得分:1)
试试这个:
from selenium.webdriver.common.action_chains import ActionChains
next_btn = driver.find_element_by_xpath('//span[@class="MuiButton-label" and contains(text(),"Next")]')
actions = ActionChains(driver)
actions.move_to_element(next_btn).perform()
如果这没有帮助 - 尝试添加一个简单的
time.sleep(5)
在点击那个按钮之前
答案 2 :(得分:1)
你可以直接用JS点击
button = chrome.find_element_by_xpath('//*[@id="gatsby-focus-wrapper"]/main/div[2]/div[2]/div[2]/div/div/div[2]/div/form/div[3]/div/div/div/button')
chrome.execute_script("arguments[0].click();", button)
答案 3 :(得分:0)
您可以按照我在另一个问题中的建议点击它,使用 xpath
并等到它可以点击:
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Next')]"))).click()
但在点击此按钮之前,您必须接受 cookie:
wait = WebDriverWait(driver, 15)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'AGREE')]"))).click()
为此,您需要导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By