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.
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()
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()
I think that I understood you. You want to do the curiosity’s route.
I found the xpath that you need
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
Answered By – javier Piña