无法在Selenium上找到永久覆盖的解决方案

时间:2018-11-20 15:10:32

标签: python python-3.x selenium firefox

我正在寻找一种针对特定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()

我有例外

  

selenium.common.exceptions.ElementClickInterceptedException:消息:元素....在点(841.5,483.25)不可点击,因为另一个元素.....使它模糊了

因此,我进行了一些挖掘工作,发现大部分内容似乎来自永久性覆盖问题,但是用下面的内容替换了最后一行并没有单击指定的按钮

element = browser.find_element(By.XPATH, button)
browser.execute_script("arguments[0].click();", element)

预期的行为

找到一段代码,可以使用以下XPath = '//*[@id="num-pad"]/button[3]'

单击指定的按钮

1 个答案:

答案 0 :(得分:1)

我有几次相同的问题...

最适合您的解决方案是使用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()

希望这对您有所帮助!