Assertion Error in Python, Though both List i am comparing are same

  assert, list, python

Please i need your help with the following code. I am trying to verify that the options in the Select Dropdown is as expected.

def getListOfExcess(self):
expected_excess = ["Nil excess", "US$250 per annum", "US$500 per annum", "US$800 per claim",
"US$1,000 per annum", "US$1,600 per claim", "US$2,500 per annum", "US$5,000 per annum",
"US$10,000 per annum"]
for excesses in expected_excess:
print(excesses)
# excess_dropdown_list = [element.text for element in
# self.driver.find_elements_by_xpath("//div[@name=’pExcess’]/div[2]/div/div/div/select")]
#
# print(*excess_dropdown_list)

excess_list = self.driver.find_elements_by_xpath("//div[@name='pExcess']/div[2]/div/div/div/select")

excess = []
for matched_element in excess_list:
    text = matched_element.text
    excess.append(text)
    if excess in excess_list and excess in excesses:
        print(matched_element, 'Excess type for Bronze are correct')
    else:
        print(matched_element, 'Excess type for Bronze are NOT correct')
    print(text)
    return text

the OutPut from my terminal is

Running method level setUp

Nil excess

US$250 per annum

US$500 per annum

US$800 per claim

US$1,000 per annum

US$1,600 per claim

US$2,500 per annum

US$5,000 per annum

US$10,000 per annum

<selenium.webdriver.remote.webelement.WebElement (session="bc5d64e85c3d5318f0cd5c15dc083fdb", element="ec21f533-a4eb-4fb9-944c-12d9ba9f05b9")> Excess type for Bronze are NOT correct

Nil excess

US$250 per annum

US$500 per annum

US$800 per claim

US$1,000 per annum

US$1,600 per claim

US$2,500 per annum

US$5,000 per annum

US$10,000 per annum

PASSEDRunning method level tearDown

Running one time tearDown

Though the List looks same but i am unable to assert that the content are same.

What am i getting wrong please.

I will greatly appreciate your help

Source: Python Questions

LEAVE A COMMENT