I am creating unit tests for my Django application in Selenium Webdriver.
I have an AJAX method that removes a topic from a database. I am trying to figure out how to verify that a deleted topic is no longer present on the page.
I am trying to catch an exception that should be thrown when Webdriver cannot find the element: selenium.common.exceptions.NoSuchAttributeException
Instead, I see an error:
*** URLError: <urlopen error timed out>
Here is how I installed the tests:
from selenium import webdriver from django.utils import unittest class TestAuthentication(unittest.TestCase): scheme = 'http' host = 'localhost' port = '4444' def setUp(self): self._driver = webdriver.Firefox() self._driver.implicitly_wait(10) def login_as_Kallie(self): # Kallie has manual login self._driver.get('http://localhost:8000/account/signin/') user = self._driver.find_element_by_id('id_username') user.send_keys("Kallie") password = self._driver.find_element_by_id('id_password') password.send_keys('*********') submit = self._driver.find_element_by_id('blogin') submit.click() def test_Kallie_can_delete_topic(self): self.login_as_Kallie() self._driver.find_element_by_link_text("Topic to delete").click() self._driver.find_element_by_xpath("/html/body/div/div[4]/div/div/div[2]/div/table/tbody/tr/td[2]/div/div[3]/span[5]/a").click() self._driver.find_element_by_class_name('dialog-yes').click() self._driver.get("http://localhost:8000/questions/") # this is the Python exception to catch: selenium.common.exceptions.NoSuchAttributeException self.assertRaises('selenium.common.exceptions.NoSuchAttributeException', self._driver.find_element_by_link_text("Topic to delete")) def tearDown(self): self._driver.quit()
How can I check if a page element is missing?
source share