i create a small program in python using selenium module.
here is my code :
while True:
try:
btnOptions = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/...."))).click()
firstElement = driver.find_elements(By.XPATH, "//*[text()='Click']")
if not firstElement:
tnTrash = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[text()='Move']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,
"/html/body/..."))).click()
else:
firstElement.click()
except NoSuchElementException:
break
the loop should do:
Step 1 : find the BtnOption button -> btnOptions = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/...."))).click()
the menu opens, in this menu there can be either elemnt1 or element2; never both at the same time. for example,
element1 is :
WebDriverWait(driver, 10).until(driver.find_elements(By.XPATH, "//*[text()='element1']"))
element2 is :
WebDriverWait(driver, 10).until(driver.find_elements(By.XPATH, "//*[text()='element2']"))
step 2 : if element 1 is found, then we click on it and restart the loop at the beginning. if it is element2 that is found, click on it and restart the loop at the beginning.
when it's a post to delete, element1 appears in the drop-down menu, if it's a profile photo, element2 appears in the drop-down menu.
for the moment my program continues as long as it finds element1, if it is element2 which is present it stops with an error telling me that element1 was not found
I thought of that but it still doesn't work :
while True:
try:
btnOptions = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div..."))).click()
WebDriverWait(driver, 20).until(driver.find_element(By.XPATH("//*[text()='move to trash']"))).click() or WebDriverWait(driver, 20).until(driver.find_element(By.XPATH("//*[text()='Do not show in profile']"))).click()
except NoSuchElementException:
break