Home > Software design >  Selenium cant find elements in specific website
Selenium cant find elements in specific website

Time:12-22

I don't find the element in specific website (enter image description here

CodePudding user response:

The elements you trying to access are inside an iframe, so you need to switch to that iframe in order to access these elements.
The following code works:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)

wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)

url = "https://insurconnect.b3.com.br/menu-web/ctp/TelaPrincipalCetip21"
driver.get(url)

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#main")))

wait.until(EC.element_to_be_clickable((By.ID, "e1"))).send_keys("my_first_input")
wait.until(EC.element_to_be_clickable((By.ID, "e2"))).send_keys("my_second_input")
wait.until(EC.element_to_be_clickable((By.ID, "e3"))).send_keys("my_third_input")
wait.until(EC.element_to_be_clickable((By.ID, "Entrada"))).click()

The result before clicking the submit button is:

enter image description here

  • Related