中的文本我的問題:能夠檢測到警告框已打開,請驗證警報內的文本,確認文本並關閉警報。然後,返回並更正無效的電子郵件。Python/Selenium:切換到提醒並驗證
我的測試是註冊用戶的測試。我需要驗證有人可能輸入錯誤的數據或不匹配的數據。在這種情況下,我輸入一封電子郵件並驗證首先輸入的電子郵件。如果它們不匹配,將出現一個彈出窗口,提醒用戶檢查他們輸入的電子郵件地址以及它們是否匹配。到目前爲止,我所能得到的只是一個錯誤。
錯誤:
E UnexpectedAlertPresentException: Message: u'Modal dialog present' ; Stacktrace: Method nsCommandProcessor.prototype.execute threw an error in file:///var/folders/1j/x3cxkrqn3sscdyq0t36169hr0000gn/T/tmpTCqMgm/extensions/[email protected]/components/command_processor.js
我想我的代碼會處理這個問題,但都能跟得上。如果有人能指出我的,對你很明顯,錯誤我會很感激。
我的整個測試代碼:
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 unittest, time, re
class ChallengeTests(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(5)
self.base_url = "https://www.testpage.com"
self.verificationErrors = []
self.accept_next_alert = True
# SIGN UP NEW USER
def test_00_sign_up(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("remail").send_keys("[email protected]")
driver.find_element_by_id("remail_confirm").send_keys("[email protected]")
driver.find_element_by_id("next").click()
alert = self.driver.switch_to_alert()
alert = self.assertTrue(self.is_text_present("The email addresses you entered"))
driver.find_element_by_id("remail_confirm").send_keys("[email protected]")
driver.find_element_by_id("registration_button").click()
# NON TESTS
def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what) # to find page elements
except NoSuchElementException, e: return False
return True
def is_text_present(self, text):
try:
body = self.driver.find_element_by_tag_name("body") # find body tag element
except NoSuchElementException, e: return False
return text in body.text # check if the text is in body's text
def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException, e:
return False
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
的新版本,你試過註釋掉隱等待和運行測試呀? – Greg