vendredi 1 novembre 2019

IF/ELSE give wrong result because of "wrong" element found

I'm using Python/Selenium in PyCharm

After step where I'm creating new filter and check if it created successfully, I want to delete it and check if it also was successful.

First I created code and after it successfully ended my test I checked website, but still my created filter was there. After that I put first three rows to see what variables will be printed out and I see that IF statement not working properly. What kind of problem could be here?

# check if created filter appear in all filter list 
element = driver.find_element_by_xpath("//span[contains(., 'Filter created by automated tests')]") 
assert element.text == filter_name 
element.click()

# check if filter is deleted
print("Element: ", element)
print("Filter: ", filter_name)

if element == filter_name:
    print("Filter not deleted, there is problem, check test case")
else:
    print("Filter deleted successfully")

Result what I get:

Element:  <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="32acd5e6-3a2e-4dba-a4f5-83c19400851e", element="4434f045-6b6d-4bd9-95c5-51a3b584b26a")>
Filter:  Filter created by automated tests
Filter deleted successfully

Aucun commentaire:

Enregistrer un commentaire