How to find a page element using Selenium?

51 Views Asked by At

enter image description here

driver=webdriver.Chrome()
driver.get("https://compass.tinkoff.ru/")
driver.maximize_window()
driver.implicitly_wait(20)

elem = driver.find_element(By.XPATH, '//button[text()="Открыть 
полную карту"]').click()
time.sleep(20)

phone = driver.find_element(By.XPATH, "//[@automation-id='phone- 
input']")
phone.send_keys("12345678")
time.sleep(20)

So i added a photo of html, and need to find the element and add a phone number in an empty field. Whatever i tried (through ID or CLASS_NAME) the element cannot be found/

1

There are 1 best solutions below

0
Akzy On

The element you're looking for is inside an iframe

Try this.

from selenium import webdriver
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

options = Options()
options.add_argument("start-maximized")   
driver = webdriver.Chrome(options=options)        
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//*[@id='app']")))

driver.maximize_window()

# switch to the iframe..
driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR, "iframe"))

# using wait for the element..
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//button[.='Открыть всю карту']"))).click()

# switch to the main window ...
driver.switch_to.default_content()

phone_input = driver.find_element(By.XPATH, "//input[@role='textbox']")
phone_input.send_keys("99999999")