I want to be able to click a certain element with selenium. I am using the following link: https://www.rivm.nl/media/smap/eenzaamheid.html
I want to be able to select each and every county/province within the map with a for loop.
The map itself I located with:
wijk_keuze = WebDriverWait(driver2nd,20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='highcharts-container ']//*[name()='svg']")
so far so good. However when I want to select a county/province this is where my problems start.
The counties/provinces live in the following element:
<g class="highchairs-series-group">
within this parent element I want to loop through each child element (being the counties/provinces). The counties/provinces elements look like this:
<g class="highcharts-series highcharts-series-0 highcharts-map-series highcharts-tracker" transform="translate(79,10) scale(1 1)" style="cursor:pointer;" clip-path="url(#highcharts-5p0c896-1)" role="region" tabindex="-1" aria-label="Delfzijl, series 1 of 4. Map with 0 areas.">
every county-element looks the same except the aria-label. (Delfzijl is an example of a county/province)
I was able to locate the "download-element" on the map, so I assumed to follow a similar process. The download element is located and clicked by doing the following:
Indicator_keuze.select_by_index(index)
download = WebDriverWait(driver2nd, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='highcharts-container ']//*[name()='svg']//*[name()='g' and @aria-label='View export menu']//*[name()='rect']")))
download.click()
WebDriverWait(download, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='highcharts-menu']//*[contains(text(),'XLS downloaden')]"))).click()
I tried locating the above element by doing the following:
wijk_keuze = WebDriverWait(driver2nd,20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='highcharts-container ']//*[name()='svg']//*[name()='g' and aria-label='Delfzijl, series 1 of 4. Map with 0 areas.']")))
This however results in a time out error.
So, how would I be able to loop through and click on each different county/province?
Couple of comments I could make here, but the main one might be:
<g class= [name()='g'
This won't match. Name looks for the attribute name="", ie <div name="g"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.