skip to Main Content

I’m trying to locate an element on a page. If I do Inspect Element, I can see the HTML code and the element id = username, but when I view page source, there is only Javascript code. Any idea on how to see the HTML page instead?

This is the page: https://pje.tjmg.jus.br/pje/login.seam

That is my code:

username_input = WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.ID, 'username')))
username_input.clear()
username_input.send_keys(cpf)

3

Answers


  1. It’s inside an iframe.

    <iframe id="ssoFrame" name="ssoFrame" class="sso-frame" src="https://pje.tjmg.jus.br/pje/authenticateSSO.seam"></iframe>
    

    Try the page in the iframe instead: https://pje.tjmg.jus.br/pje/authenticateSSO.seam

    Login or Signup to reply.
  2. Desired element(@id=username) is wrapped within an iframe. You first need to switch into the iframe and then perform any action.

    enter image description here

    Refer the below working code:

    import time
    
    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.maximize_window()
    
    driver.get("https://pje.tjmg.jus.br/pje/login.seam")
    wait= WebDriverWait(driver,30)
    wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"ssoFrame")))
    username_input = wait.until(EC.element_to_be_clickable((By.ID, 'username')))
    username_input.clear()
    username_input.send_keys("text")
    time.sleep(30)
    

    Result:

    enter image description here

    Switching back to default content: To come out of iframe use the code below.

    driver.switch_to.default_content()
    
    Login or Signup to reply.
  3. The Username field is 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://pje.tjmg.jus.br/pje/login.seam")
        WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#ssoFrame")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#username"))).send_keys("MPenner")
        
      • Using XPATH:

        driver.get("https://pje.tjmg.jus.br/pje/login.seam")
        WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='ssoFrame']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='username']"))).send_keys("MPenner")
        
    • 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:

    MPenner


    Reference

    You can find a couple of relevant discussions in:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search