'Selenium: element not interactable, Google Maps automation
I just created a Selenium code to get the travel time between 2 set of coordinates in Google Maps. "output.txt" is a list of coordinates such as "19.5860438,-99.2715737 to 19.6028627,-99.185743". When I run the code it appears "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable", but if I change this part of code
search = driver.find_element_by_name("q")
search.send_keys(y)
search.send_keys(Keys.RETURN)**
by changing the "y" with the actual coordinate the code works perfectly, but if it tries to loop in the list the error appears.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
File = "output.txt"
a_file = open(File)
lines = a_file.readlines()
for x in range(2):
for y in lines:
Path = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(Path)
driver.get("https://www.google.com/maps")
search = driver.find_element_by_name("q")
search.send_keys(y)
search.send_keys(Keys.RETURN)
try:
transporte = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".vxq1Hc:nth-child(3) .Wnt0je-urwkYd-WAutxc-icon"))
)
except:
driver.quit()
driver.execute_script("arguments[0].click();", transporte)
time.sleep(3)
directions = driver.find_element_by_class_name("xB1mrd-T3iPGc-iSfDt-n5AaSd")
with open('tiempo.txt', 'w') as f:
f.write(directions.text)
driver.quit()
Does anyone knows why this happens?
Output.txt is the following list
19.5860438,-99.2715737 to 19.6028627,-99.185743
19.6569881,-99.0622077 to 19.6028627,-99.185743
19.6131191,-98.9537177 to 19.6028627,-99.185743
19.4916535,-99.2277299 to 19.6028627,-99.185743
19.5304865,-99.2809449 to 19.6028627,-99.185743
19.5424037,-99.0557252 to 19.6028627,-99.185743
19.4941883,-98.9365922 to 19.6028627,-99.185743
19.4076984,-99.1923676 to 19.6028627,-99.185743
19.4514075,-99.2727052 to 19.6028627,-99.185743
19.4504363,-99.0018235 to 19.6028627,-99.185743
19.4060793,-99.0722047 to 19.6028627,-99.185743
19.3700488,-99.2070883 to 19.6028627,-99.185743
19.3284059,-99.1695301 to 19.6028627,-99.185743
19.3381165,-99.040433 to 19.6028627,-99.185743
19.3747191,-99.0926181 to 19.6028627,-99.185743
19.3023707,-99.1955472 to 19.6028627,-99.185743
19.1873019,-99.1646482 to 19.6028627,-99.185743
19.2369048,-99.0544416 to 19.6028627,-99.185743
19.2842243,-99.0118695 to 19.6028627,-99.185743
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
