Selenium WebDriverException 中的空错误消息

Posted

技术标签:

【中文标题】Selenium WebDriverException 中的空错误消息【英文标题】:Empty error message in Selenium WebDriverException 【发布时间】:2013-05-11 17:01:42 【问题描述】:

我正在尝试使用 Selenium/BeautifulSoup 对网页进行单元测试。虽然我无法通过 Google 搜索,但我遇到了错误。

selenium.common.exceptions.WebDriverException: Message: ''

我使用的是便携式版本的 Firefox 和代理。

import urllib2
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import time
import sys

def getItemDivs(url):
    profile = webdriver.FirefoxProfile()
    profile.set_preference("general.useragent.override","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/21.0")
    profile.set_preference("network.proxy.http", "proxy.example.com")

    ffbin = webdriver.firefox.firefox_binary.FirefoxBinary('C:\\FirefoxPortable\\App\\Firefox\\firefox.exe')

    # IT FAILS ON THE NEXT LINE
    driver=webdriver.Firefox(profile, firefox_binary=ffbin)
    driver.implicitly_wait(30)

    # THIS LINE CONTAINS A VALID COOKIE, BUT IT HAS BEEN REMOVED FOR THIS QUESTION.
    driver.add_cookie(<<mycookie>>)
    base_url = url
    verificationErrors = []
    accept_next_alert = True

    driver.get(base_url)
    scrap1 = driver.page_source
    soup = BeautifulSoup(scrap1)

这个问题类似于this one,但是,在那个问题中,他们的第一个请求是成功的。我没有成功。

什么会导致这种类型的异常但将消息留空?

【问题讨论】:

感谢 "ffbin = webdriver.firefox.firefox_binary.FirefoxBinary('C:\\FirefoxPortable\\App\\Firefox\\firefox.exe') # 在下一行失败 driver=webdriver .Firefox(profile, firefox_binary=ffbin)" 【参考方案1】:

问题是我没有设置network.proxy.port。添加此行解决了问题:

profile.set_preference("network.proxy.port", "80")

【讨论】:

以上是关于Selenium WebDriverException 中的空错误消息的主要内容,如果未能解决你的问题,请参考以下文章

Selenium-IDE,Selenium-RC ,Selenium grid以及 Selenium-Core

selenium是啥?

Python爬虫 Selenium -- Selenium元素定位Selenium访问元素信息Selenium交互

Selenium学习Selenium 总结

Selenium - 简介

java selenium selenium 介绍