简体   繁体   English

无法单击元素 Selenium python

[英]Unable to click element Selenium python

I want to be able to click a certain element with selenium.我希望能够使用 selenium 单击某个元素。 I am using the following link: https://www.rivm.nl/media/smap/eenzaamheid.html我正在使用以下链接: 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.我希望能够使用 for 循环 map 内的每个县/省 select。

The map itself I located with: map 本身位于:

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.但是,当我想 select 一个县/省时,这就是我的问题开始的地方。

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.除了 aria-label 之外,每个县元素看起来都一样。 (Delfzijl is an example of a county/province) (Delfzijl 是县/省的示例)

I was able to locate the "download-element" on the map, so I assumed to follow a similar process.我能够在 map 上找到“下载元素”,所以我假设遵循类似的过程。 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' <g 类= [name()='g'

This won't match.这将不匹配。 Name looks for the attribute name="", ie <div name="g" name 查找属性name="",即<div name="g"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM