Traceback (most recent call last):
File “D:/selenium/xuehu.py”, line 23, in <module>
text= browser.find_element_by_class_name(“user-name”).text
File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 426, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 784, in find_element
‘value’: value})[‘value’]
File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 249, in execute
self.error_handler.check_response(response)
File “C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:”class name”,”selector”:”user-name”}
(Session info: chrome=51.0.2704.106)
(Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.3.9600 x86_64)

这种问题在selenium脚本中比较常见,是页面未加载出来,就执行了下一句的代码,所以报错,必须要加个等待时间,就OK了 

版权声明:本文为parker007原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/parker007/p/8856613.html