jeudi 12 août 2021

IF CONDITION doesn't work between Popup accept and another Element, just 1 of them works. Selenium python

I am trying to do if else condition for Selenium Python with popup.

i am checking a website, sometimes appears popup to make sure that u want start the TASK.

and sometimes appears the Button direct without Popup.

i want the code to switch to popup and click it if its appears and click the button if not.

Here is my 2 Tries to make it.

if  WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'buttonStartNew'))):
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'buttonStartNew'))).click()

else:
        WebDriverWait(driver, 5).until(EC.alert_is_present())
        driver.switch_to.alert.accept()

in this example he just run the first IF condition and doesn't turn to Else if he didn't match the IF.it just click the button if it appears, if not it will crash without go to the else.

if  WebDriverWait(driver, 5).until(EC.alert_is_present()):
        driver.switch_to.alert.accept()

else:
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'buttonStartNew'))).click

in this try he run also just the first IF Condition if found it and doesn't go to the else. also here he is running just the popup click, if it appers.

when it crashed, there is no a message reason. Selenium python mistake is empty

Can Someone help me?

Aucun commentaire:

Enregistrer un commentaire