余温_zey 发表于 2017-9-18 10:43:59

python selenium 连接到firefox后只打开网页后就没有反应了

在windows上配置好python3.5 + selenium 3.5 ,运行一个小程序(打开firefox,打开百度首页),在打开firefox之后就没有反应了,也不会打开网页,等待很久后报错connect refused,这个是为什么?

Miss_love 发表于 2017-9-18 11:06:43

大概率是因为不兼容

神仙也考试 发表于 2017-9-18 10:59:58

1、上代码,看看是不是你的代码有问题!
2、看看是不是Firefox的驱动不兼容你电脑上安装的Firefox的版本!

testuser023 发表于 2017-9-18 11:09:14

selenium3.5不支持firefox默认的driver,建议使用selenium2.X
参考资料:
http://www.cnblogs.com/ppppying/p/6143803.html

清晨一缕阳光 发表于 2017-9-18 11:13:10

贴上代码和报错信息!

.chao 发表于 2017-9-18 16:37:49

是不是没有下载驱动软件

骑车去看海 发表于 2017-9-18 17:27:51

我的win 10 代码不报错,启动起来浏览器就报异常。

余温_zey 发表于 2017-9-18 20:51:03

Miss_love 发表于 2017-9-18 11:06
大概率是因为不兼容

不清楚哇。

余温_zey 发表于 2017-9-18 20:51:54

神仙也考试 发表于 2017-9-18 10:59
1、上代码,看看是不是你的代码有问题!
2、看看是不是Firefox的驱动不兼容你电脑上安装的Firefox的版本!

代码:
# coding = utf-8
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw").send_keys("selenium")
browser.find_element_by_id("su").click()
browser.quit()


报错信息:
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe C:/Users/Administrator/PycharmProjects/untitled/webtest/test_1.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/webtest/test_1.py", line 3, in <module>
    browser = webdriver.Firefox()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 154, in __init__
    keep_alive=True)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

余温_zey 发表于 2017-9-18 20:55:04

.chao 发表于 2017-9-18 16:37
是不是没有下载驱动软件

下了的,:'(

余温_zey 发表于 2017-9-18 20:55:55

清晨一缕阳光 发表于 2017-9-18 11:13
贴上代码和报错信息!

代码:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw").send_keys("selenium")
browser.find_element_by_id("su").click()
browser.quit()

告警信息:
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe C:/Users/Administrator/PycharmProjects/untitled/webtest/test_1.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/webtest/test_1.py", line 3, in <module>
    browser = webdriver.Firefox()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 154, in __init__
    keep_alive=True)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

余温_zey 发表于 2017-9-18 21:52:47

余温_zey 发表于 2017-9-18 20:51
代码:
# coding = utf-8
from selenium import webdriver


已经解决,是Firefox的驱动版本不对,多谢

余温_zey 发表于 2017-9-18 21:53:26

Miss_love 发表于 2017-9-18 11:06
大概率是因为不兼容

果然是,我的Firefox驱动的版本不对,换了个最新的就好了:lol
页: [1]
查看完整版本: python selenium 连接到firefox后只打开网页后就没有反应了