【问题标题】:Selenium python slider bouton Element Not Visible ExceptionSelenium python滑块按钮元素不可见异常
【发布时间】:2019-07-07 09:43:17
【问题描述】:

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

我想点击“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

【问题讨论】:

  • import sleep and put between clicks time.sleep(1) ,并检查它是否仍然出现同样的问题,如果没有帮助,请在开始使用元素之前滚动到网站的底部(也在 driver.get() 之后等待
  • 好的,谢谢:)

标签: javascript python selenium selenium-webdriver web-scraping


【解决方案1】:

我可以看到您的 Xpath 是正确的。但它不能交互。 请尝试它应该工作的动作链。当您在 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 个滑动按钮单击选项。让我知道这是否有效。

【讨论】:

  • 我试了,没有错。但金额不变。
  • 我已经更新了答案,这绝对可以工作
  • 没有错误,但金额没有变化。 i.stack.imgur.com/5KhLy.png
  • 奇怪。它在我的笔记本电脑上发生了变化。您能否延迟一些时间并删除无头选项进行测试。对我来说,单击同一按钮 3 次后显示 12.075。
  • 对不起,它没有用 headless 改变。让我检查一下有什么问题。它在没有 headless 的情况下工作。
猜你喜欢
  • 1970-01-01
  • 2015-05-03
  • 1970-01-01
  • 2018-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-18
相关资源
最近更新 更多