goldsilvy
goldsilvy

Reputation: 41

Python - selenium - click on tab

I am trying to scrape GPS coordinates off an embedded Google map on a property website (link)

The relevant data is under this block of HTML:

<a target="_blank" rel="noopener" href="https://maps.google.com/maps?ll=51.517204,-0.126447&amp;z=15&amp;t=m&amp;hl=en-GB&amp;gl=US&amp;mapclient=apiv3" title="Open this area in Google Maps (opens a new window)" style="position: static; overflow: visible; float: none; display: inline;"><div style="width: 66px; height: 26px; cursor: pointer;"><img alt="" src="https://maps.gstatic.com/mapfiles/api-3/images/google_white5_hdpi.png" draggable="false" style="position: absolute; left: 0px; top: 0px; width: 66px; height: 26px; user-select: none; border: 0px; padding: 0px; margin: 0px;"></div></a>

However that bit is located on the Map & Nearby tab, which I am having troubles accessing

I have tried the following:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option('useAutomationExtension', False)

PATH = r"...\chromedriver.exe"
driver = webdriver.Chrome(executable_path=PATH, options=chromeOptions, desired_capabilities=chromeOptions.to_capabilities())

url = 'https://www.primelocation.com/new-homes/details/55357965?search_identifier=d10d089a335cc707245fb6c924bafbd2'
driver.get(url)
link = driver.find_element_by_link_text("Map & Nearby")
actions = ActionChains(driver)
actions.click(link)

And few other combinations of find_element_xyz, however with no success

The question I have is: how can I access the Map & Nearby tab?

Upvotes: 0

Views: 588

Answers (1)

SeleniumUser
SeleniumUser

Reputation: 4177

Try below solution to avoid synchronization error:

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC\

url = 'https://www.primelocation.com/new-homes/details/55357965?search_identifier=d10d089a335cc707245fb6c924bafbd2'
driver.get(url)
element = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, "//a[@id='ui-id-3']//span")))
element.click();

or

url = 'https://www.primelocation.com/new-homes/details/55357965?search_identifier=d10d089a335cc707245fb6c924bafbd2'
driver.get(url)
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'Map & nearby')]")))
element.click();

Upvotes: 2

Related Questions