【发布时间】:2022-08-19 04:30:50
【问题描述】:
我试图在具有react-leaflet 地图的网页上获取元素。页面导入如下:
// Map.js component
import { Map, TileLayer, GeoJSON, Pane } from \'react-leaflet\'
...
return(
<Map
<TileLayer ... />
/>
)
然后 DOM 看起来像这样:
<div class=\"leaflet-container\">
<div class=\"leaflet-pane\">
<div class=\"leaflet-pane custom-pane\">
<svg class=\"leaflet-zoom-animated\">
<g>
<path class=\"leaflet-interactive\">...</path>
<path class=\"leaflet-interactive\">...</path>
<path class=\"leaflet-interactive\">...</path>
<path class=\"leaflet-interactive\">...</path>
<path class=\"leaflet-interactive\">...</path>
</g>
</svg>
</div>
</div>
</div>
当我在浏览器控制台中查询元素时,我得到了所有 <path> 元素
document.querySelectorAll(\'.leaflet-interactive\')
// NodeList(5)
但是当我尝试从我的 Python 脚本中获取时,它找不到元素:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_options(\"detach\", True)
driver = webdriver.Chrome(options=chrome_options)
wait = WebDriverWait(driver, 10)
wait.until(EC.url_contains(\"map\"))
driver.get(url) # the webpage url
wait.until(EC.url_contains(f\"{latitude}/{longitude}\"))
# the following step fails
elements = wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, \"leaflet-interactive\")))
不幸的是,它没有给我任何有用的错误(实际上没有例外)。
我正在查看其他问题,但看起来我的代码是正确的 - https://stackoverflow.com/a/63329510/11228445
这是传单渲染页面的问题吗?我看不到任何正在渲染的图层或 iframe。
标签: python selenium selenium-webdriver leaflet