如何与硒中的地图元素互动

发布于 2025-02-07 22:14:11 字数 1427 浏览 2 评论 0原文

我最近开始与Python的Selenium Chrome Driver合作,当试图与NASA map 接口。我的目标是按时间顺序迭代和集中在地图上的所有路点,遵循好奇心的路线。我能找到的最好的解决方案是使用工具栏元素,因为该元素的行为将映射核算为单击时的给定航点。

但是,我不确定如何将硒用于此目的,因为您似乎首先必须鼠标单击特定的路点才能触发工具栏元素,然后该元素将屏幕集中在航向点上。理想的情况是我可以通过编程编辑工具栏元素,以在给定整数范围内的所有航点上进行迭代。

目前,我能够找到工具栏元素并单击它,但是我不确定如何更改其指向的路点ID。如果证明这太困难了,我将接受替代解决方案。

接口示例:

“示例”

当前实现:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

import time

driver = webdriver.Chrome()
driver.get("https://mars.nasa.gov/maps/location/?mission=MSL&site=NOW")

time.sleep(5)  # to allow for page loading

# the ID for the toolbar element
elem = driver.find_element_by_id("mainDescPointInner") 
elem.click()

for i in range(1, 1000):

     # change element target

     elem.click()

更新:

使用以下建议,我能够使用以下方法来解析和与地图元素进行交互:

l = driver.find_elements(By.XPATH,
    '//*[@id="map"]//descendant::*[name()="svg"]//descendant::*[@class="waypoints leaflet-interactive"]')

for i in l:
    ActionChains(driver).click(i).perform()

I've recently started to work with the Selenium Chrome driver in Python, and I ran into an issue when trying to interact with a NASA map interface. I aim to follow Curiosity's route by iterating and centering over all the waypoints on the map chronologically. The best solution I was able to find is to use a toolbar element, as this element's behaviour centres the map to a given waypoint on click.

However, I am unsure how to use Selenium for this purpose, as it seems you first have to mouse click on a specific waypoint to trigger the toolbar element, and then this element centres the screen on the waypoint. The ideal scenario would be for me to edit the toolbar element programmatically, to iterate over all waypoints in a given integer range.

Currently, I was able to find the toolbar element and click it, but I am unsure how to change the waypoint ID to which it is pointing. If this proves too difficult, I am open to alternative solutions.

Interface example:

Example

Current implementation:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

import time

driver = webdriver.Chrome()
driver.get("https://mars.nasa.gov/maps/location/?mission=MSL&site=NOW")

time.sleep(5)  # to allow for page loading

# the ID for the toolbar element
elem = driver.find_element_by_id("mainDescPointInner") 
elem.click()

for i in range(1, 1000):

     # change element target

     elem.click()

Update:

Using the advice given below, I was able to parse and interact with map elements by using the following approach:

l = driver.find_elements(By.XPATH,
    '//*[@id="map"]//descendant::*[name()="svg"]//descendant::*[@class="waypoints leaflet-interactive"]')

for i in l:
    ActionChains(driver).click(i).perform()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2025-02-14 22:14:11

我认为我了解你。您想做好奇心的路线。
我发现您需要//*[@ID =“ map”] // descendant ::*[name()=“ svg”] ]
此XPATH为您提供了路线的所有元素,稍后使用方法 find_elements 和您的句子可以得到好奇心路线的所有要点。

l = driver.find_elements(......)
#iterate through list
for i in l:
  # to do things

I think that I understood you. You want to do the curiosity's route.
I found the xpath that you need //*[@id="map"]//descendant::*[name()="svg"]//descendant::*[name()="path"]
This xpath gives you all elements of the route, later with the method find_elements and the sentence for you could get all points of the curiosity's route.

l = driver.find_elements(......)
#iterate through list
for i in l:
  # to do things
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文