我正在寻找关于该特定 website 的解决方案点击 带有 XPath = '//*[@id="num-pad"]/button[3]' 的按钮,但我一直失败
当前行为
使用这段代码
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()
timeout=20
browser.set_page_load_timeout(timeout)
browser.get("https://www.amundi-ee.com/psf/#login")
button='//*[@id="num-pad"]/button[3]'
login='//*[@id="identifiant"]'
cbutton='//*[@id="maploginKeyboard"]/area[8]'
WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.XPATH, button)))
browser.find_element(By.XPATH, button).click()
我有异常(exception)
selenium.common.exceptions.ElementClickInterceptedException: Message: Element ....is not clickable at point (841.5,483.25) because another element..... obscures it
所以我在互联网上搜索了一下,我发现的大部分内容似乎都来自永久性覆盖问题,但是用下面的内容替换最后一行不会单击指定的按钮
element = browser.find_element(By.XPATH, button)
browser.execute_script("arguments[0].click();", element)
预期行为
找到一段允许点击指定按钮的代码,XPath = '//*[@id="num-pad"]/button[3]'
请您参考如下方法:
我遇到过同样的问题好几次了...
我最好的解决方案是使用 ActionChains。
我已将它添加到您的代码中并且对我有用!
这是工作片段:
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()
timeout=20
browser.set_page_load_timeout(timeout)
browser.get("https://www.amundi-ee.com/psf/#login")
button='//*[@id="num-pad"]/button[3]'
login='//*[@id="identifiant"]'
cbutton='//*[@id="maploginKeyboard"]/area[8]'
WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.XPATH, button)))
print("found the element")
my_buttton = browser.find_element(By.XPATH, button)
action = ActionChains(browser)
action.move_to_element_with_offset(my_buttton, 5, 5)
action.click()
action.perform()
希望这对您有所帮助!
