【发布时间】: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 row 和 column 指向表中的位置,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