how can i make the condition it does not go through this code if there is the next button because there are page does not contain the next button
I would like a condition for the next button to check if it exists or not how I can do it
url = "https://www.tripadvisor.fr/Restaurants-g23084688-Beardsley_New_Brunswick.html"
driver.get(url)
time.sleep(3)
with open("details.txt","w") as filenam:
if hasattr(driver.find_element(By.XPATH, './/a[@class="nav next rndBtn ui_button primary taLnk"]').text,"Next"):
while True:
try :
container = driver.find_elements(By.XPATH,"//a[@class='Lwqic Cj b']")
for j in range(len(container)):
li=container[j].get_attribute("href")
links1.append(li)
print(li)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, './/a[@class="nav next rndBtn ui_button primary taLnk"]'))).click()
except:
break
# else:
container = driver.find_elements(By.XPATH,"//a[@class='Lwqic Cj b']")
for j in range(len(container)):
li=container[j].get_attribute("href")
links1.append(li)
print(li)
for l in links1:
filenam.writelines(l+"\n")