-1

new to all of this, so I apologize if it's a stupid question.

here is all i am trying to do:

nxt_btn = driver.find_element_by_xpath('/html/body/main/article/section/form/div[2]/button')
nxt_btn.click()
time.sleep(2)
vote_check = driver.find_element_by_xpath('/html/body/main/article/section/form/div[1]/div[2]/div/div/fieldset/div/div/div[2]/div/input')
vote_check.click()
time.sleep(2)
nxt_btn = driver.find_element_by_xpath('/html/body/main/article/section/form/div[2]/button')
nxt_btn.click()
driver.quit()

and it returns:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/main/article/section/form/div[1]/div[2]/div/div/fieldset/div/div/div[2]/div/input"}


(Session info: chrome=84.0.4147.125)

i've tried changing the wait time, choosing different elements, and checking to see if it is in an iframe, which if it is, i can't find it by just going up the path.

soup
  • 1

1 Answers1

1

Instead of sleep use Selenium explict waits

 element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.XPATH, "XPATH"))

Conditions you can use are:

  1. visibility_of_element_located
  2. text_to_be_present_in_element
  3. element_to_be_clickable
Amruta
  • 1,128
  • 1
  • 9
  • 19