Can't get login input element with selenium python

Question:

I was trying to some selenium program but now I’m stuck at logging in.

  • Here is code => https://pastebin.com/ykTcd1rb
  • When code execute last line of code (username = driver.find_element(By.ID, 'Login')) I get an error (selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="Login"]"})
  • Here is Element which i trying to get <input aria-invalid="false" type="text" class="form-control" name="Login" id="Login" required="">

Please Help me

Asked By: Gaming with Dayfit

||

Answers:

As I see, this command more = driver.find_element(By.ID, "dropdownTopRightMenuButton") can’t be executed since that element is not visible.
Also, it’s not a good idea to use hardcoded sleeps. WebDriverWait expected_conditions should be used instead.
The following code worked for me:

from selenium import webdriver
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:webdriverschromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://portal.librus.pl/rodzina/synergia/loguj"

driver.get(url)
wait.until(EC.element_to_be_clickable((By.ID, "cookieBoxClose"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.login-before-btn"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[name='email']"))).send_keys("my_username")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[name='password']"))).send_keys("my_password")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']"))).click()

This, of cause, failed to login because I have no valid credentials, but with correct credentials this should work

Answered By: Prophet