I'm using Selenium on http://seattle.bestparking.com/ to click through the parking garage markers (red, grey, blue), with the intention of opening the pop-up info window, so I can then scrap the info (on the "rate" page in the pop-up window). See my code at the end.
However, it appears that each of the garage marker's inner HTML changes (!!), after you click any other garage marker of the same color, then closing it (due to content reloading).
E.g.: when running my code, "Motif Seattle" garage shows up as div id = daily_colored_marker_577
. But after any other marker of the same color is clicked on, "Motif Seattle" shows up as div id = daily_colored_marker_1042
... and keeps on changing.
This makes it seemingly impossible to iterate through all the markers that I've selected (result of find_elements_by_class
), since it will throw the following type or error when reaching the 2nd element in the selected list:
WebDriverException: unknown error: Element <div
class="daily_colored_marker_n_a" id="daily_colored_marker_344" onmouseover="show_hide_balloonWindowMonthly('', 'IMPARK', 'IMPARK M Street
Garage', '344', 400, 'n_a', offsetPosition('daily_colored_marker_344')...
</div> is not clickable at point (708, 543). Other element would receive the
click: <div class="daily_colored_marker_grey"...
My code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome()
driver.get('http://seattle.bestparking.com/')
driver.maximize_window()
'''Tells driver to wait until the "I understand" button to be clickable'''
wait = WebDriverWait(driver, 30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//*
[@id='calendar_navigation_hint']/button")))
'''makes the disclaimer pop-up and the left menu go away, to reveal more of
the map'''
driver.find_element_by_xpath("//*@id='calendar_navigation_hint']
/button").click()
time.sleep(2)
driver.find_element_by_xpath("//*
[@id='map_left_panel_min_max_btn_div_oa']").click()
time.sleep(2)
'''zooms out one level'''
driver.find_element_by_xpath("//*
[@id='google_maps_zoom_control_minus_id']").click()
time.sleep(5)
'''find all the red markers and click on them'''
all_red = driver.find_elements_by_css_selector("div.daily_colored_marker_n_a")
time.sleep(3)
for x in range(0,len(all_red)):
all_red[x].click()
time.sleep(2)
driver.find_element_by_xpath("//*[@id='marker_window_close_text']").click()
time.sleep(3)