我遇到过一个场景,它似乎只有在特定条件下才会在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
环顾四周,这个问题已经在前面的一个问题中提到并解释过了。我的特定场景的问题是,这不是警报的结果,所以当我试图关闭警报时。。。
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)
其中行和列指向表中的位置&值表示期望的值。在Firefox上,它在代码的expected_condition()部分失败。然而,Chrome运行此代码时没有任何错误。
您在selenium
2.43和firefox
36之间遇到兼容性问题。
目前最简单的选择是将硒升级到2.45:
pip install --upgrade selenium