标题:python selenium无法定位到元素?敢问大神怎么处理?
取消只看楼主
冷酷的双曲线
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-7-5
 问题点数:0 回复次数:0 
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
搜索更多相关主题的帖子: sleep python click File line 
2021-08-09 04:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506455-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.093858 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved