1

After feeding the search bar with "Safety" keyword, I am trying to get to the page associated with this link_text. But error unable to find element is coming.

from selenium import webdriver
import pandas as pd
import re
import time
driver = webdriver.Chrome("C:\\Users\\tanmay\\Downloads\\chromedriver.exe")
driver.get("https://www.tripadvisor.in/Hotel_Review-g304551-d299120-Reviews-or10-The_Lalit_New_Delhi-New_Delhi_National_Capital_Territory_of_Delhi.html")

print("Name :",driver.find_element_by_id("HEADING").text)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("//*[@id='TABS_REVIEWS']/span").click()
Element = driver.find_element_by_class_name("query_elem")
Element.send_keys("Safety")
driver.find_element_by_css_selector('.ui_icon.search.search-icon').click()
driver.execute_script("window.scrollTo(0,2020);")
driver.find_element_by_link_text(driver.find_element_by_class_name("searchHit").text).click()
1
  • 1
    Is the element visible on the page when you are trying to click it. And also check if that element is not in a iframe and there is no overlay that block clicking the element.
    – chesthar
    Sep 16, 2018 at 13:43

1 Answer 1

1

After clicking on the search icon, there is a AJAX request to fetch the data. You would need to wait its end to query the text.

One way of doing it easily is to wait for the searchHit element to be visible.

wait = WebDriverWait(driver, 10) #10 seconds timeout
searchHit = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".searchHit"))) # Wait until the element is clickable for 10 seconds at most
searchHit.click()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.