Selenium findElement不适用于谷歌地图

Selenium findElement not working for google maps

本文关键字:谷歌地图 适用于 不适用 findElement Selenium      更新时间:2023-09-26

无法在谷歌地图中找到元素。

<g-map id="map-contain" style="position: relative; overflow: hidden; transform: translateZ(0px); background-color: rgb(229, 227, 223);">
    <div class="gm-style" style="position: absolute; left: 0px; top: 0px; overflow: hidden; width: 100%; height: 100%; z-index: 0;">
        :::::
        ::::::
        ::::::
    </div>
<g-map>

我尝试过这个,但没有运气选择带有"gm 风格"类的div

this.driver.findElement(By.xpath('//div[@class="gm-style"]'));

如何在 g-map 标签中获取元素?

我会尝试通过 id 匹配外部 g-map 标签并获取其子级。Id 应该是唯一的,而类大多不是