madsobel
madsobel

Reputation: 3257

Python Unittest - If assertEqual then?

I have used the Selenium IDE to record a "perfect" scenario for some datamining I am doing, I have exported the script to Python Unittest, and out-of-the box it works fine.

How ever I want to run over a table, and if a value on a particular field matches a text, I would like to test if the content in another field within the same row is not equal to "NULL". The mapping of the fields is done. But I am having trouble testing for the equality to get the logic working..

Ideally I want to do something like this, but this is not working:

if self.assertEqual("FOO", driver.find_element_by_xpath("//div[@id='passedindata']/table/tbody/tr/td[2]/div[3]/div/table/tbody/tr[13]/td[8]").text):
    self.assertNotEqual("NULL", driver.find_element_by_xpath("//div[@id='passedindata']/table/tbody/tr/td[2]/div[3]/div/table/tbody/tr[13]/td[3]").text)

Upvotes: 1

Views: 876

Answers (1)

Egat
Egat

Reputation: 97

assertEqual is not used to check equality. An assertion will either be true, or raise an exception. You want to make an assertion only when a particular element is equal to "FOO".

if ("FOO" == driver.find_element_by_xpath("//div[@id='passedindata']/table/tbody/tr/td[2]/div[3]/div/table/tbody/tr[13]/td[8]").text):
    self.assertNotEqual("NULL", driver.find_element_by_xpath("//div[@id='passedindata']/table/tbody/tr/td[2]/div[3]/div/table/tbody/tr[13]/td[3]").text)

Upvotes: 2

Related Questions