0

I am trying to automate a login on my website using selenium.

I am accessing this website : http://front-desk.fr/users/accounts/login/?next=/

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

chrome_path = r"C:\Users\gaeta\OneDrive\Bureau\chromedriver.exe"

class FrontDesk:
    def __init__(self,username,password):
        self.username = username
        self.password = password
        self.bot = webdriver.Chrome(chrome_path)

    def login(self):
        bot = self.bot
        bot.get("http://front-desk.fr/users/accounts/login/")
        time.sleep(5)
        email = bot.find_element_by_class_name('textinput textInput form-control')
        email.send_keys(self.username)



ed = FrontDesk('myemail@gmail.com', 'password1234')
ed.login()

But an error occur :

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".textinput textInput form-control"}

This is my website so I am sure of the class, and I have looked on SO and the answers were talking about Iframe, I do not have any.

I have tried with class, id etc. everything work except it does not fill the input.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 2
    Compound class names are not permitted. Have a look at: https://stackoverflow.com/questions/37771604/selenium-compound-class-names-not-permitted – Casper Jan 17 '20 at 05:39
  • 1
    Does this answer your question? [Selenium Compound class names not permitted](https://stackoverflow.com/questions/37771604/selenium-compound-class-names-not-permitted) – hiropon Jan 17 '20 at 05:43
  • @hiropon Thanks ! I used a different kind of filter and it works now, thanks again ! –  Jan 17 '20 at 05:44

2 Answers2

0

This error message...

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".textinput textInput form-control"}

...implies that the ChromeDriver was unable to locate the desired element with in the Browsing Context i.e. Chrome Browser session.


You need to take care of a couple of things as follows:

  • Using find_element_by_class_name() you won't be able to pass multiple class names. Passing multiple classes you will face the error as:

    Message: invalid selector: Compound class names not permitted
    
  • You can find a relevant detailed discussion in Invalid selector: Compound class names not permitted using find_element_by_class_name with Webdriver and Python

  • You could have used the following CSS_SELECTOR as a valid selector instead:

    email = bot.find_element_by_css_selector('input.textinput.textInput.form-control')
    
  • But the CSS_SELECTOR above doesn't identifies the desired element uniquely.


To send a character sequence within the Identifiant field you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#id_login"))).send_keys(self.username)
    
  • Using XPATH:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='id_login']"))).send_keys(self.username)
    
  • 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
    

tl; dr

You can find a relevant detailed discussion on NoSuchElementException in Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome

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

The HTML source is not valid, there are plenty of unclosed tags such as those for your stylesheets. Fix these up then try again.

Stephen Straton
  • 709
  • 5
  • 12
  • Hmm I don't where you're going with that... it's valid, selenium is just looking for id or tag... I managed to make it work by calling with the "name" filter. I must say, your answer is not useful. –  Jan 17 '20 at 05:06
  • Try putting the html through an xml validator and you'll see what I mean with regards to it being invalid because of the unclosed tags. This is no longer important as you've solved your issue. – Stephen Straton Jan 17 '20 at 05:21