I am trying to make such a program, first go to duckduckgo.com and search on the search bar Best hotel in india,then find my website link then click the link to my website.
from time import sleep
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox(executable_path=r'C:\Users........\geckodriver.exe')
driver.get("https://duckduckgo.com")
time.sleep(10)
search_field = driver.find_element_by_id('search_form_input_homepage')
search_field.clear()
search_field.send_keys('best hotel in india')
search_field.submit()
time.sleep(10)
driver.find_element_by_link_text("More Results").click()
time.sleep(10)
driver.find_element_by_link_text("More Results").click()
time.sleep(10)
driver.find_element_by_link_text("More Results").click()
time.sleep(10)
driver.find_element_by_link_text("More Results").click()
time.sleep(10)
driver.find_element_by_link_text('//my hotel url//').click()
time.sleep(60)
driver.quit()
but i'm getting following error
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:......
time.sleep(10)is wasteful. You should do instead once at the beginningdriver.implicitly_wait(10). Then when you do a find_element, the driver will implicitly wait for up to 10 seconds for the element to appear before timing out. But, of course, if the element shows up before the 10 seconds, which it usually does, you do not needlessly wait longer than you have to.