1

I am trying to get data from a password protected website with Selenium. However I get stuck right in the beginning at login with the following error message:

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

The name I use is correct for sure, I inspected the website. Including waiting time did not help either...

My code is:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from getpass import getpass



driver = webdriver.Chrome()


driver.get("https://clearing.apcs.at/emwebapcsem/startApp.do")

print(driver.title)
print(driver.current_url)


# create an object for searchbox
username=driver.find_element_by_name("username")
password=driver.find_element_by_name("password")
# typte the input
username.send_keys("XXXXXX")
password.send_keys("XXXXXX")
driver.find_element_by_name('login').click()

Any suggestions would be appreciated.

1 Answer 1

1

To send a character sequence to the Benutzer and Passwort field as the elements are within an <frame> 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://clearing.apcs.at/emwebapcsem/startApp.do')
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"frame[title='menu']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.loginContentBoxInput[name='username']"))).send_keys("Endre")
      driver.find_element_by_css_selector("input.loginContentBoxInput[name='password']").send_keys("Endre")
      
    • Using XPATH:

      driver.get('https://clearing.apcs.at/emwebapcsem/startApp.do')
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//frame[@title='menu']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='loginContentBoxInput' and @name='username']"))).send_keys("Endre")
      driver.find_element_by_xpath("//input[@class='loginContentBoxInput' and @name='password']").send_keys("Endre")
      
  • 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:

clearing


Reference

You can find a couple of relevant discussions in:

Sign up to request clarification or add additional context in comments.

Comments

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.