0

I can't search for the element to see if it's even there because Python throws in an error and halts the script, even when using try/catch.

while True:
    jobinfo1 = driver.find_elements(By.XPATH, "//ul[@class = 'jobsearch-ResultsList css-0']/li")
    for xx in jobinfo1:
        jobinfo.append(xx)
    isPresent = len(driver.find_elements(By.XPATH, "//a[@data-testid = 'pagination-page-next']")) > 0
    if isPresent != True:
        break
    else:
        driver.find_element(By.XPATH, "//a[@data-testid = 'pagination-page-next']").click()

Below is an alternative to try and handle the exception, both don't work.

# while True:
#     jobinfo1 = driver.find_elements(By.XPATH, "//ul[@class = 'jobsearch-ResultsList css-0']/li")
#     for xx in jobinfo1:
#         jobinfo.append(xx)
#     ok = driver.find_elements(By.XPATH, "//a[@data-testid = 'pagination-page-next']")
#     if len(ok) > 0:
#         driver.find_element(By.XPATH, "//a[@data-testid = 'pagination-page-next']").click()
#     else:
#         break

I hope it's a small syntax issue but it's giving me a hay day.

Rahul K P
  • 15,740
  • 4
  • 35
  • 52

0 Answers0