I have a dropdown menu and I need to check its entries. If there is no entry , I can add new entries, if there is only one entry I remove it and add new entries and when I have many entries (>=2) I cannot proceed to adding entries. I can check it via person_rem_btn. If I have only one button doc_person_table:0:person_rem_btn I can proceed If I have a second button doc_person_table:1:person_rem_btn I cannot proceed.
I get this exception:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='frmMain:doc_person_table:1:person_rem_btn']/span[1]"}
However, that's the point, this element may not be available, I just check its existence. I would appreciate any help. Here is my code:
if driver.find_element_by_xpath("//*[@id='frmMain:doc_person_table:1:person_rem_btn']/span[1]") == True:
print ("there are already many entries")
driver.close()
elif (driver.find_element_by_xpath("//*[@id='frmMain:doc_person_table:1:person_rem_btn']/span[1]") == False and driver.find_element_by_xpath("//*[@id='frmMain:doc_person_table:0:person_rem_btn']/span[1]") == True):
print ("there is only one entry, it will be removed to proceed")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='frmMain:doc_person_table:0:person_rem_btn']/ span[1]"))).click()
else:
print ("there is no entry, you can proceed")