I'm trying to do the test to learn Allure, and to assure that the test is passed, the button has to be INVISIBLE. It first clicks 1st button to make 2nd button appear. Then click 2nd button - so same (2nd button disappears). Here it is: http://the-internet.herokuapp.com/add_remove_elements/
My code would look like this (below), it clicks the 1st button, 2nd button - and after it should check that button DELETE is not visible anymore. Instead it interrupts whole code and throws error that element was not found/located. How do you make it so it will not interrput/cancel whole codeblock when it doesn't find this button?
class TestPage:
def test_button(self):
s=Service('C:\Program Files\chromedriver.exe')
browser = webdriver.Chrome(service=s)
browser.get("http://the-internet.herokuapp.com/")
browser.maximize_window()
time.sleep(1)
add = browser.find_element(By.XPATH, "/html/body/div[2]/div/ul/li[2]/a")
add.click()
time.sleep(1)
button = browser.find_element(By.XPATH, "/html/body/div[2]/div/div/button")
button.click()
time.sleep(1)
deleteButton = browser.find_element(By.XPATH, "/html/body/div[2]/div/div/div/button")
deleteButton.click()
deleteCheck = browser.find_element(By.XPATH, "/html/body/div[2]/div/div/div/button").is_displayed()
if deleteCheck == False:
assert True
else:
assert False
time.sleep(1)
browser.close()
Here's edited code (with last step trying to go to main page):
def test_button(self):
s=Service('C:\Program Files\chromedriver.exe')
browser = webdriver.Chrome(service=s)
browser.get("http://the-internet.herokuapp.com/")
browser.maximize_window()
wait = WebDriverWait(browser, 3)
time.sleep(1)
add = browser.find_element(By.XPATH, "/html/body/div[2]/div/ul/li[2]/a")
add.click()
time.sleep(1)
button = browser.find_element(By.XPATH, "/html/body/div[2]/div/div/button")
button.click()
time.sleep(1)
browser.save_screenshot('buttons.png')
time.sleep(1)
delete = browser.find_element(By.XPATH, "/html/body/div[2]/div/div/div/button")
delete.click()
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[onclick*='delete']"))).click()
time.sleep(0.5)
if not browser.find_elements(By.CSS_SELECTOR, "button[onclick*='delete']"):
assert True
else:
assert False
time.sleep(0.5)
browser.get("http://the-internet.herokuapp.com/")