2016-11-22 61 views
0

我试图用下面的代码执行此操作。它应该转到https://www.google.co.jp/并点击侧边菜单上的YouTube链接。Python Selenium - 尝试点击链接时出现'ElementNotVisibleException'错误

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 
+0

没有关于语言的问题。你写的东西已经可以理解了。我现在改进了一下,并且在开始时删除了道歉,因为语法正常。祝你好运! – Bobby

回答

0

你需要等待的元素被点击,使用element_to_be_clickable

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

如果不工作,我会建议验证您正在使用正确的选择器,或增加等待时间。

相关问题