from selenium import webdriver
from info import user_name, pass_word
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
driver = webdriver.Firefox() #opening web browser
driver.get('https://tuportal.temple.edu/') #going to temple wbsite
username = driver.find_element_by_id("username") #finds space where to enteruser
password = driver.find_element_by_id("password") #same for password
username.send_keys(user_name()) #enters my username
password.send_keys(pass_word()) #enters my password
driver.find_element_by_name("_eventId_proceed").click()#click login
#waits until the element for student tools tab is found
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "layout_8")))
element.click()
time.sleep(3)
driver.switch_to_frame("iFrame_AppTupChannelsStudentRegistration")#accessing iframe
#scrolls
element = driver.find_element_by_id('StudentRegistration_3')
driver.execute_script("return arguments[0].scrollIntoView();", element)
#end of scroll
element.click() #click look up classes
所有代码一直运行到最后一行,“element.click()” 我收到了错误 - >
追踪(最近一次通话): 文件“C:\ Users \ Karl \ Desktop \ project \ signin.py”,第31行,in element.click()#click查找类 文件“C:\ Users \ Karl \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py”,第80行,点击 self._execute(Command.CLICK_ELEMENT) 文件“C:\ Users \ Karl \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py”,第628行,在_execute中 return self._parent.execute(command,params) 文件“C:\ Users \ Karl \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py”,第312行,执行中 self.error_handler.check_response(响应) 在check_response中输入文件“C:\ Users \ Karl \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ errorhandler.py”,第242行 提出exception_class(消息,屏幕,堆栈跟踪) selenium.common.exceptions.ElementNotInteractableException:消息:元素无法滚动到视图中
令人困惑的部分是导致错误的行之前的2行
element = driver.find_element_by_id('StudentRegistration_3')
driver.execute_script("return arguments[0].scrollIntoView();", element)
完全没有发生错误的说法,他们滚动我试图点击的按钮,最后一行进入视图。 任何人都可以找到解决方案 我正在使用python 3,selenium和Firefox更新到当前版本。