vendredi 2 avril 2021

Click element only if it appears

I am trying to bypass a problem in my program which uses selenium and chromedriver. In practice, the program crashes because, for example, 3 times out of 10 ( i use cicle while), a different from the usual one appears. So I thought of adopting the following solution, which unfortunately does not work (so I give you the idea):

if WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='example']"))) ==true :

    driver.find_element_by_xpath("//a[@class='example']").click()
else
     break

I thought that in that way, only when he found the element and therefore the true condition, he clicked, otherwise the program continues

Aucun commentaire:

Enregistrer un commentaire