<p>要回答您的特定问题,您不能像往常一样与<code>svg</code>元素交互。为此,您必须使用<code>xPath</code>,就像我在示例中提供的那样。您也不能像往常一样单击这些元素,但可以使用<code>ActionChains</code>。你知道吗</p>
<pre><code>wait = WebDriverWait(driver, 5)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"#mapDiv_zoom_slider .esriSimpleSliderIncrementButton"))).click()
time.sleep(3)
items = driver.find_elements_by_xpath("//*[name()='svg']//*[name()='circle']")
i = 0
for item in items:
try:
time.sleep(1)
ActionChains(driver).move_to_element(item).click(item).perform()
except Exception:
print("Can't click")
</code></pre>
<p>这段代码工作,每个元素将被单击,直到地图将被放大。在其中一个元素的地图放大,它不工作之后。为什么?我还没发现,但你可以自己找,或者问其他问题,我们会尽力帮助你。你知道吗</p>
<p><strong><em>注意:</em></strong>您必须添加一些导入:</p>
<pre><code>from selenium.webdriver.common.action_chains import ActionChains
import time
</code></pre>
<p><strong><em>编辑:</em></strong>我发现了问题,您必须在单击后关闭每个弹出窗口,然后它才能工作。工作代码如下:</p>
<pre><code>wait = WebDriverWait(driver, 5)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#mapDiv_zoom_slider .esriSimpleSliderIncrementButton"))).click()
time.sleep(3) # wait until all elements will be ready
items = driver.find_elements_by_xpath("//*[name()='svg']//*[name()='circle']")
for item in items:
time.sleep(0.5) # small pause before each iteration
ActionChains(driver).move_to_element(item).click(item).perform()
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@title = 'Close']"))).click()
</code></pre>
<p>我没有找到避免<code>time.sleep()</code>的方法,可能在这种特殊情况下是不可能的。你知道吗</p>