I was trying to scrape a website where you need to pass the address to get the coordinates of that address. I was able to pass the address and display the latitude and longitude in the browser but unable to retrieve it.
Here is how it goes.
Using this code I got the latitude and longitude displayed in the browser.
from selenium import webdriver
chrome_path = r"C:\Users\Himanshu Poddar\Desktop\chromedriver.exe"
url = 'https://www.latlong.net/convert-address-to-lat-long.html'
wd = webdriver.Chrome(chrome_path)
wd.get(url)
# Get the input element to which address is to be passed
inputElement = wd.find_element_by_xpath('//input[@placeholder="Type address here to get lat long"]')
# send the address
inputElement.send_keys('Domlur, Bangalore')
# click on get the coordinates button
wd.find_element_by_id('btnfind').click()
Now the lat and lon are displayed:
How do I get the latitude and longitude which are generated dynamically in the input field and therefore couldn't find in the inspect element.
The inspect element for latitude and longitude are
Latitude
<div class="col-6 m2">
<label for="lat">Latitude</label>
<input type="text" name="lat" id="lat" placeholder="lat coordinate">
</div>
Longitude
<div class="col-6 m2">
<label for="lng">Longitude</label>
<input type="text" name="lng" id="lng" placeholder="long coordinate">
</div>
which does not contain the displayed latitude and longitude.
EDIT : I am looking for the function that returns the latlong value, can we do it using the execute_script of selenium