I am attempting to enter text into the "Search address or location" search field on this website – https://www.verizon.com/coverage-map/
It seems to be unable to locate the element however I’ve tried multiple variations for the XPATH and locating by other methods with no success. Below is the code snippet, also commented is the code i have working for another website with no issues.
driver.get("https://www.verizon.com/coverage-map/")
address_input3 = wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id='root_search_container']")))
# also tried address_input3 = wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id='search_input']")))"""
address_input3.clear()
address_input3.send_keys(address)
address_input3.send_keys(Keys.RETURN)
time.sleep(5)
driver.save_screenshot("Verizon.png")
time.sleep(5)
"""driver.get("https://www.att.com/maps/wireless-coverage.html")
address_input = wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id='searchLocation']")))
address_input.clear()
address_input.send_keys(address)
address_input.send_keys(Keys.RETURN)
time.sleep(5)
driver.save_screenshot("AT&T.png")
time.sleep(5)"""
HTML:
>Solution :
There is an IFRAME which has wrapped the desired element. You need to first switch into the IFRAME and then perform any actions.
Check the below working code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://www.verizon.com/coverage-map/")
driver.maximize_window()
# create WebDriverWait object
wait = WebDriverWait(driver, 20)
# switch into iframe
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@src,'gismaps')]")))
# Enter text into search box
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='search_input']"))).send_keys("Your text here")
# Use below code to come out of IFRAME once all actions are performed within that IFRAME
driver.switch_to.default_content()
Result:

