我遇到了一个JS Alert框的问题,它被认为是有效的,但突然之间突然出现了这个问题。
selenium.common.exceptions.WebDriverException: Message: [JavaScript Error: "e is null" {file: "file:///var/folders/8t/n1tmxt2s4cjc_g3hc_4sm6_x3_m7_l/T/tmpTmBrlm/extensions/fxdriver@googlecode.com/components/command-processor.js" line: 7854}] ...
我不知道你们是否可以帮助我。这是python selenium代码,浏览器是Firefox 32到34。
我的代码在
之下def testArticleDekExternalLinksTest(self):
"""Practitest id :305"""
addArticlePage = AP.AddArticlePage(self.driver,"m.php?t=articles")
addArticlePage.getRandomEditorialArticle()
keys = "https://www.google.com/?gws_rd=ssl"
addArticlePage.clickDekExternalLinks()
alert = self.driver.switch_to.alert
print alert
alert.send_keys(keys)
alert.accept()
self.assertTrue(addArticlePage.save(), "cannot save an Article")
self.driver.refresh()
addArticlePage.clickHtmlView(0)
time.sleep(2)
assert keys in addArticlePage.getDekContentUrlStripped()
addArticlePage.loadUrl(addArticlePage.getPreviewUrl())
articlePage = ArticlePage.ArticlePage(self.driver)
如果我尝试打印警报,我可以看到警报对象,即使添加时间也没有帮助,最奇怪的部分是它以前工作而现在不工作.. Selenium版本是2.45.0
答案 0 :(得分:1)
确定。对我来说这似乎是一个等待问题。尝试使用explicit wait并在某个时候发出警报
def testArticleDekExternalLinksTest(self):
"""Practitest id :305"""
addArticlePage = AP.AddArticlePage(self.driver,"m.php?t=articles")
addArticlePage.getRandomEditorialArticle()
keys = "https://www.google.com/?gws_rd=ssl"
addArticlePage.clickDekExternalLinks()
WebDriverWait(self.driver, 10).until(EC.alert_is_present())
alert = self.driver.switch_to.alert
print alert
alert.send_keys(keys)
alert.accept()
self.assertTrue(addArticlePage.save(), "cannot save an Article")
self.driver.refresh()
addArticlePage.clickHtmlView(0)
time.sleep(2)
assert keys in addArticlePage.getDekContentUrlStripped()
addArticlePage.loadUrl(addArticlePage.getPreviewUrl())
articlePage = ArticlePage.ArticlePage(self.driver)
另一个相关的thread