这里我需要删除一些记录。当我选择所有项目并单击删除按钮。它显示流行像“你确定要删除这个”,OK&没有按钮。然后我需要单击确定按钮并删除所选项目。但我使用下面的代码没有点击OK按钮。如果有人知道这个答案,请告诉我..
class login(unittest.TestCase):
def setUp(self):
self.driver= webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://ww.example.com"
self.verificationErrors = []
self.accept_next_alert = True
def close_all_popups(driver):
driver.window_handles
for h in driver.window_handles[1:]:
driver.switch_to_window(h)
driver.close()
driver.switch_to_window(driver.window_handles[0])
def test001_login(self):
driver=self.driver
driver.delete_all_cookies()
driver.get(self.base_url +"/")
driver.find_element_by_xpath("//*[@id='form-div']/form/input[1]").clear()
driver.find_element_by_xpath("//*[@id='form-div']/form/input[1]").send_keys("xxxx")
driver.find_element_by_xpath("//*[@id='form-div']/form/input[2]").clear()
driver.find_element_by_xpath("//*[@id='form-div']/form/input[2]").send_keys("xxxxx")
driver.find_element_by_xpath("//*[@id='form-div']/form/input[3]").click()
driver.find_element_by_xpath("//*[@id='navigation']/li[4]/a").click()
driver.find_element_by_xpath("//*[@id='selectall']").click()
driver.find_element_by_xpath("//a[text()='Delete']").click()
self.close_all_popups()
def is_element_present(self, how, what):
try:self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert.text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
答案 0 :(得分:0)
我认为您在点击删除后没有调用此方法
self.close_alert_and_get_its_text(self)