【问题标题】:Python Selenium - getting 'ElementNotVisibleException' error when trying to click on linkPython Selenium - 尝试单击链接时出现“ElementNotVisibleException”错误
【发布时间】:2026-02-10 23:00:01
【问题描述】:

我正在尝试使用以下代码执行此操作。它应该转到https://www.google.co.jp/ 并单击侧面菜单上的YouTube 链接。

import time
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
google=driver.get("https://www.google.co.jp/")
youtube=WebDriverWait(driver,300)
.until(EC.presence_of_element_located
((By.XPATH,".//*[@id='tsf']/div[2]    /div[3]/center/input[2]")))
youtube.click()

它返回此错误:

[[ElementNotVisibleException]] ERROR

【问题讨论】:

  • 语言没问题。你写的已经可以理解了。由于语法没问题,我对其进行了一些改进,并在开始时删除了道歉。祝你好运!

标签: python selenium firefox


【解决方案1】:

您需要等待元素可点击,使用element_to_be_clickable

.until( EC.element_to_be_clickable((By.XPATH, ".//*[@id='tsf']/div[2]    /div[3]/center/input[2]")) );

如果这不起作用,我建议您验证您是否使用了正确的选择器,或者增加等待时间。

【讨论】:

    最近更新 更多