0

im new to python and recently got into selenium , i made small projects for linkedin or twitter with it from a tutorial but now i wanted to do smth for my work(finance) and my problem is:

On this website: https://mfinante.gov.ro/domenii/informatii-contribuabili/persoane-juridice/info-pj-selectie-dupa-cui

When i try to find a element by any selector(name xpath css selectors etc) it tells me there is no such element

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
from selenium.common.exceptions import NoSuchElementException

URL = 'https://mfinante.gov.ro/domenii/informatii-contribuabili/persoane-juridice/info-pj-selectie-dupa-cui'


s = Service('My chromedriver path')
driver = webdriver.Chrome(service = s)

driver.get(URL)
driver.maximize_window()
time.sleep(3)
cui_entry = driver.find_element(By.CSS_SELECTOR,'.col-sm-4 p input')
cui_entry.send_keys('23484xxx')

What i want it to do is to write this code where it says Introduceti codul unic de identificare (numeric): but it seems like im doing something wrong

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To send a character sequence to the Enter the unique identification code (numeric) field as the elements are within an iframe so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get("https://mfinante.gov.ro/domenii/informatii-contribuabili/persoane-juridice/info-pj-selectie-dupa-cui")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#_com_liferay_iframe_web_portlet_IFramePortlet_INSTANCE_AAFALwmoH3eD_iframe")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='cod']"))).send_keys("23484")
      
    • Using XPATH:

      driver.get("https://mfinante.gov.ro/domenii/informatii-contribuabili/persoane-juridice/info-pj-selectie-dupa-cui")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='_com_liferay_iframe_web_portlet_IFramePortlet_INSTANCE_AAFALwmoH3eD_iframe']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='cod']"))).send_keys("23484")
      
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

mfinante


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352