python selenium无法定位到元素?敢问大神怎么处理?
程序代码:
""" 用 selenium 实现对中国大学mocc的登录 """ from selenium import webdriver from time import sleep fox = webdriver.Firefox() url ='https://www.' fox.get(url) sleep(3) # 点击登录按钮,弹出登录界面 fox.find_element_by_css_selector('#auto-id-1628452551743').click() sleep(1) # 选择其他登录方式 fox.find_element_by_css_selector('#login-cnt > div > div > div > div.ux-login-set-scan-code_ft > span').click() # 获取账号框和密码框,输入密码 fox.find_element_by_css_selector('#auto-id-1628452775609').send_keys('*************') sleep(1) fox.find_element_by_css_selector('#auto-id-1628452775612').send_keys('*************') sleep(1) fox.find_element_by_css_selector('#dologin').click() sleep(1) print(fox.current_url) print(fox.page_source) sleep(5) sleep(2) fox.quit()
报错信息如下:
Traceback (most recent call last):
File "D:\pythonProject2\实战python网络爬虫\selenium的使用\selenium_03.py", line 13, in <module>
fox.find_element_by_css_selector('#auto-id-1628452551743').click()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 598, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
Message: Unable to locate element: #auto-id-1628452551743