【问题标题】:For Python, getting WebDriverException: Message: u'[JavaScript Error: "e is null"对于 Python,获取 WebDriverException: Message: u'[JavaScript Error: "e is null"
【发布时间】:2015-03-04 18:27:30
【问题描述】:

我遇到了一个似乎只在某些条件下在 Firefox 上失败的场景。在我的代码中...

    driver.get(url('/Points/Inputs/'))
    assertRowTrue(driver, 2, 11, "True")

我收到错误消息...

E           WebDriverException: Message: u'[JavaScript Error: "e is null" {file:
 "file:///tmp/anonymous7279155570809486473webdriver-profile/extensions/fxdriver@
googlecode.com/components/command-processor.js" line: 7854}]\'[JavaScript Error:
 "e is null" {file: "file:///tmp/anonymous7279155570809486473webdriver-profile/e
xtensions/fxdriver@googlecode.com/components/command-processor.js" line: 7854}]\
' when calling method: [nsICommandProcessor::execute]\nBuild info: version: \'2.
43.0\', revision: \'597b76b\', time: \'2014-09-09 20:52:14\'\nSystem info: host:
 \'8efca6f08729\', ip: \'172.17.0.3\', os.name: \'Linux\', os.arch: \'amd64\', o
s.version: \'3.13.0-24-generic\', java.version: \'1.7.0_65\'\nDriver info: drive
r.version: unknown' ; Screenshot: available via screen

环顾四周,在上一个问题here 中提到并解释了这个问题。我的特定场景的问题是它不是警报的结果,所以当我尝试关闭警报时......

driver.switch_to_alert().dismiss()

...我收到了NoAlertPresentException

在 Selenium 解决此问题之前,如果警报不是罪魁祸首,是否有办法绕过此错误?

更新(2015 年 6 月 6 日)

尝试下面列出的答案工作了一段时间,但又回到了我看到的原始错误。这是我的一个失败的测试示例。

嘿@alecxc。这是一个失败的例子。我访问了一个特定的网页,以验证 [表格中的] 行是否包含我期望的信息。为此,我使用了自己的定义 assertRowTrue()

assertRowTrue(driver, 2, 11, "Online")

这个def,我已经创建了代码。

def assertRowTrue(driver, row, column, value):
    try:
        WebDriverWait(driver, 30).until(
            expected_conditions.text_to_be_present_in_element((By.XPATH, "//tr["+str(row)+"]/td["+str(column)+"]/div"), value)
        )
    except TimeoutException:
        raise Exception("ERROR : VALUE NOT EQUAL TO EXPECTED VALUE \""+value+"\".  ACTUAL VALUE:  ", driver.find_element_by_xpath("//tr["+str(row)+"]/td["+str(column)+"]/div").text)

..where rowcolumn 指向表中的位置,value 表示预期的值。在 Firefox 上,它在代码的 expected_condition() 部分失败。但是,Chrome 运行此代码时不会出现任何错误。

【问题讨论】:

  • 你用的是哪个火狐版本?
  • Mozilla Firefox 36.0
  • 我曾经遇到过一个问题,错误是由quit() 执行时出现的警报引起的。我实际上不会看到警报,因为一切都发生得太快了。我添加了关闭警报的代码,但后来我发现有时此代码执行速度太快:警报是异步创建的,但dismiss() 有时会在警报存在之前执行。 检查您是否遇到竞争条件的一种快速方法是在driver.switch_to_alert().dismiss() 之前添加time.sleep(<a few seconds>)

标签: javascript python firefox selenium selenium-webdriver


【解决方案1】:

您在selenium 2.43 和firefox 36 之间遇到兼容性问题

目前最简单的选择是将 selenium 升级到 2.45:

pip install --upgrade selenium

【讨论】:

  • 我成功将 selenium 升级到 2.45,但是当我运行我的测试场景时,它仍然失败并显示相同的错误消息。
  • @rwbyrd 只是在我删除答案之前快速检查一下:尝试将 firefox 降级到 34.0.5。
  • 抱歉,目前正在灭火。明天试试这个,然后回复你。
  • 嘿@alecxe。我刚刚完成了尝试并解决了这个问题。升级 selenium 和将 Firefox 降级到 34.0.5 的组合使相关测试成功运行。我有没有提到你很棒!?感谢您的帮助!
  • 嘿@alecxe,今天早上我又遇到了这个问题。我尝试使用 36,然后降级回 34.0.5,问题仍然存在。在这再次发生之前发生的一个变化是 Windows 7 在过去几天安装了一些下载。有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-28
  • 2022-01-14
  • 1970-01-01
  • 1970-01-01
  • 2015-11-27
  • 2015-10-07
相关资源
最近更新 更多