Je suis actuellement en train de travailler avec Selenium et je rencontre un problème lors de la déclaration d'une variable. Le problème est que si l'élément recherché pour remplir la variable n'existe pas, je souhaiterais simplement passer à autre chose plutôt qu'une erreur.
case = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/table/tbody/tr[2]/td[2]/span")
case.click()
case = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/table/tbody/tr[3]/td[2]/span")
case.click()
case = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/table/tbody/tr[4]/td[3]/span")
case.click()
case = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/table/tbody/tr[5]/td[1]/span")
case.click()
case = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/table/tbody/tr[6]/td[1]/span")
case.click()
case = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/table/tbody/tr[7]/td[2]/span")
case.click()
boutton = driver.find_element(
"xpath", "/html/body/div[1]/div[3]/div[2]/form/div/div[3]/input")
boutton.click()
A mon avis, les erreurs se produisent sur les click et pas sur les find_element, le find_element va retourner None si il ne trouve pas l'élément en question; donc le test se fera après
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Python c'est bon, mangez-en.