I have been webscraping some websites to grab there locations for webscraping practice. This code gets me down to individual city levels of a hotel brand, but whenever I use driver.execute_script("arguments[0].click();", button) in my code (as seen in the second to last line) I get this error:
JavascriptException: Message: javascript error: arguments[0].click is not a function
Below is a sample of the code that I have written thus far.
for state in state_links:
driver = Chrome(path_to_chrome_driver)
link = 'https://www.ihg.com/destinations/us/en/united-states/' + state.lower().replace(' ', '-')
driver.get(link)
city_links = driver.find_elements_by_xpath('//div[@class="countryListingContainer col-xs-12"]//ul//div//li//a//span')
city_links = [thing.text for thing in city_links]
driver.close()
for city in city_links:
driver = Chrome(path_to_chrome_driver)
link2 = 'https://www.ihg.com/destinations/us/en/united-states/' + state.lower().replace(' hotels', '').replace(' ', '-') + '/' + city.lower().replace(' ', '-')
driver.get(link2)
hotel_links = driver.find_elements_by_xpath('//div[@class="hotelList-detailsContainer"]//div//div//p//a')
hotel_links = [elem.text for elem in hotel_links]
driver.close()
for hotel in hotel_links:
driver = Chrome(path_to_chrome_driver)
driver.get(link2)
driver.implicitly_wait(15)
driver.execute_script("arguments[0].click();", hotel)
driver.implicitly_wait(10)