1

I need to fix this code. This comes with an error message saying

 NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="login_username"]"}
  (Session info: chrome=92.0.4515.159)

The below is the code

   from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    # finq credentials
    username = "[email protected]"
    password = "xxxxxxxxx"
    # initialize the Chrome driver
    driver = webdriver.Chrome(executable_path=r'C:\Users\snyder\data\chromedriver.exe')
    # head to finq login page
    driver.get("https://www.finq.com/en/login")
    # find username/email field and send the username itself to the input field
    driver.find_element_by_id("login_username").send_keys(username)
    # find password input field and insert password as well
    driver.find_element_by_id("login_password").send_keys(password)
    # click login button
    driver.find_element_by_name("submit_login").click()

1 Answer 1

1

It is in iframe, so you need to switch to it before interaction.

you can use the below css_selector to switch to iframe :

iframe[id='login']

in code :

username = "[email protected]"

driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(5)
driver.get("https://www.finq.com/en/login")
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id='login']")))
# find username/email field and send the username itself to the input field
driver.find_element_by_id("login_username").send_keys(username)
# find password input field and insert password as well
driver.find_element_by_id("login_password").send_keys(password)
# click login button
driver.find_element_by_css_selector("button[id='submit_login']").click()

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much. The code is working. but im getting an error message saying NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="submit"]"} (Session info: chrome=92.0.4515.159)
okay updated the code above. use this instead driver.find_element_by_css_selector("button[id='submit_login']").click()
seems like theres an error too. This is the message. InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified (Session info: chrome=92.0.4515.159). I have selected the specific ID's by going through inspect element option. Username and password is okay. But I feel the login name is wrong.
please use this line driver.find_element_by_css_selector("button[id='submit_login']").click() to click on login button, I could do it from my end, also I see Incorrect username or password. since the creds are not correct .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.