gpt4 book ai didi

javascript - Selenium python slider bouton 元素不可见异常

转载 作者:行者123 更新时间:2023-11-30 06:18:40 25 4
gpt4 key购买 nike

我正在尝试写入解析器以单击网站上的按钮,但我无法单击其中两个按钮。

我想点击“Elija el imports a financiar”和“Elija la mensualidad”

这是 html:https://www.cofidis.es/es/creditos-prestamos/prestamo-personal.html

python 代码:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--start-maximized')
webdriver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
url = "https://www.cofidis.es/es/creditos-prestamos/prestamo-personal.html"

webdriver.get(url)
targetSliderStep = 6.000
targetSliderStep = round(targetSliderStep * 2) / 2 # to ensure is units covered by clicking
print('target: ' + "{0:.3f}".format(targetSliderStep))
webdriver.find_element_by_xpath('//*[@id="btncerrar"]').click()
actualSliderStep = float(webdriver.find_element_by_id('I2:simuPanel.O').text.replace(' €',''))
print(actualSliderStep)
webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.mensMoreId"]').click()
webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.mensLessId"]').click()
print(actualSliderStep)

webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.mensMoreId"]').click()
webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.mensLessId"]').click()

print(webdriver.find_element_by_id('I2:simuPanel.O7').text)
webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.durMoreId"]').click()
webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.durLessId"]').click()
print(webdriver.find_element_by_id('I2:simuPanel.O7').text)

我遇到了这个错误。

ElementNotVisibleException: Message: element not interactable

最佳答案

我可以看到您的 Xpath 是正确的。但它不能交互。请尝试它应该工作的 Action 链。当您在 chrome 选项下方添加此代码时,该代码将 headless 工作。

chrome_options.add_argument('window-size=2560x1440')

代替这个

webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.mensMoreId"]').click()

请试试

 el=webdriver.find_element_by_xpath('//*[@id="I2:simuPanel.amountMoreId"]')
ActionChains(webdriver).move_to_element(el).click(el).perform()

以这种方式更改所有 4 个滑动按钮的单击选项。让我知道是否可行。

关于javascript - Selenium python slider bouton 元素不可见异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54672194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com