selenium.common.exceptions.WebDriverException:消息:在Selenium Python

时间:2017-08-18 10:09:23

标签: python selenium firefox

我正在尝试使用python运行基于selenium的自动化脚本。

当我尝试运行脚本时,我遇到了以下错误。虽然driver.quit在Internet Explorer中完美运行但在Firefox中出错,但是看起来像driver.quit()似乎存在问题。我已经搜索了这个错误但没有多少结果来创建这个问题。下面的脚本似乎有时会工作但通常会失败。由于错误信息并不能说明为什么会发生这种情况,如果有人能帮助我,我将不胜感激。

系统详细信息:

Python version = 3.6.2
Firefox version = 53 32-bit
Selenium = 3.4.3 
Geckodriver = 0.18.0 32-bit

代码块:

os.environ['PATH']=r'P:\imran-TEMS\selenium-3.4.3'
user_id=getpass.getuser()
location = "C:\\Users\\" + user_id + "\\AppData\\Local\\Mozilla Firefox\\firefox.exe" 
binary = FirefoxBinary(location)
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy',"proxy1")
profile.set_preference('network.proxy.ftp',"proxy1")
profile.set_preference('network.proxy.ssl',"proxy1")
profile.set_preference('network.proxy.socks',"proxy1")
profile.set_preference('network.proxy.http_port',8080)
profile.set_preference('network.proxy.ftp_port',8080)
profile.set_preference('network.proxy.ssl_port',8080)
profile.set_preference('network.proxy.socks_port',8080)
profile.update_preferences()

driver = webdriver.Firefox(firefox_profile=profile,firefox_binary=binary)
driver.get(link) # I have not mentioned link due to client privacy
link1=  WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "access-number")))
link1.click()
link1.send_keys('14188768')

link1=  WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,'securityNumber')))
link1.click()
link1.send_keys('2468')

link1=  WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,'internet-password')))
link1.click()
link1.send_keys('test12')

sleep(1)
link1.send_keys(Keys.RETURN)
sleep(2)
link2=WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH,"id('header')/div[1]/p[1]/a[1]/span[1]")))
link2.click()


driver.quit()

错误堆栈跟踪:

Traceback (most recent call last):
  File "P:\imran-TEMS\script\test.py", line 54, in <module>
    driver.quit()
  File "C:\Users\l096535\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\firefox\webdriver.py", line 181, in quit
    RemoteWebDriver.quit(self)
  File "C:\Users\l096535\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\remote\webdriver.py", line 551, in quit
    self.execute(Command.QUIT)
  File "C:\Users\l096535\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\remote\webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "C:\Users\l096535\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: quit

1 个答案:

答案 0 :(得分:0)

我认为将浏览器更新到最新版本可能对您有帮助,但我不确定。