dimanche 24 février 2019

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element

I have this error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="username"]

Code of session file:

def login(self, username, password):
    wb = self.app.wb
    self.app.open_home_page()
    wb.find_element_by_name("username").click()
    wb.find_element_by_name("username").clear()
    wb.find_element_by_name("username").send_keys(username)
    wb.find_element_by_xpath("//*[@id='login-form']/fieldset/input[2]").click()
    wb.find_element_by_name("password").click()
    wb.find_element_by_name("password").clear()
    wb.find_element_by_name("password").send_keys(password)
    wb.find_element_by_xpath("//*[@id='login-form']/fieldset/input[3]").click()


def is_logged_in_as(self, username):
    wb = self.app.wb
    return self.get_logged_user() == username

def get_logged_user(self):
    wb = self.app.wb
    return wb.find_element_by_xpath("//*[@id='breadcrumbs']/ul/li/a").text

My test code:

   def test_login(app):
        app.session.login("administrator", "*******")
        assert app.session.is_logged_in_as("administrator")

What could be the problem?

Aucun commentaire:

Enregistrer un commentaire