• gorgenasty

    I'm using selenium to scrape hotel reviews but struggling to click on the link of desired hotel from returned results. Here is my code. The error code was invalid selector. May I have your suggestions how to fix this problem?

    # Define name, i.e. Eden The Residence at The Sea
    name = "Eden The Residence at The Sea"
    # name = "Admiral Suites Bangkok"
    
    # Invoke Chrome and go to booking.com
    driver = webdriver.Chrome(executable_path="../drivers/chromedriver.exe")
    driver.get("https://www.expedia.com/")
    print("Accessing " + driver.title)
    print(driver.current_url)
    
    # Enter hotel name, i.e. Eden The Residence at The Sea
    print("Searching for {}.".format(name))
    time.sleep(get_random_wait())
    driver.find_element_by_css_selector("button[class='uitk-faux-input']").send_keys(name)
    time.sleep(get_random_wait())
    driver.find_element_by_css_selector("button[class='uitk-button uitk-button-small uitk-button-fullWidth uitk-button-typeahead uitk-type-left has-subtext']").click()
    
    # Click search
    print("Clicking search button.")
    time.sleep(get_random_wait())
    driver.find_element_by_css_selector("button[type='submit']").click()
    
    # Click the hotel name, i.e. Eden the Residence at The Sea
    print("Selecting {} from return list.".format(name))
    time.sleep(get_random_wait())
    # driver.find_element_by_xpath("//body/div[@id='app']/div[@id='app-layer-manager']/div[@id='app-layer-base']/div[1]/div[1]/div[1]/div[1]/main[1]/div[2]/section[2]/ol[1]/li[1]/div[1]/div[1]/a[1]").click()
    
    # results = driver.find_element_by_css_selector("h3[contains(text(), '" + name + "')]")
    results = driver.find_element_by_css_selector("h3[contains(text(), 'Eden the Residence at the Sea')]")
    
    results[0].click()
    

    https://bit.ly/38owpey

    posted in General Discussion read more

Internal error.

Oops! Looks like something went wrong!