I am writing an automated test with Selenium in Python. I do not understand why in the piece of code below the until method of WebdriverWait needs to be called twice, because otherwise the text input will not be filled. What do I need to add or delete so that the html input field is filled without the need to call to WebDriverWait.until() twice? The method looks like this:
class SomeClass:
    usernameId = 'username'
    passwordId = 'password'
    def doSomething(self, username, password):
        wait = WebDriverWait(self.driver, 10)
        sleep(2)
        # TODO: find out why one wait is not enough, and how it should be done properly.
        element = wait.until(EC.element_to_be_clickable((By.ID, self.usernameId)))
        # Why is the seconde line needed? Without it the input is not filled. It should not be?
        element = wait.until(EC.element_to_be_clickable((By.ID, self.usernameId)))
        element.send_keys(username)
        d = self.driver
        wait.until(lambda d: element.get_attribute("value") == username)
        pwdElement = wait.until(EC.element_to_be_clickable((By.ID, self.passwordId)))
        # Why is the seconde line needed? Without it the input is not filled. It should not be?
        pwdElement = wait.until(EC.element_to_be_clickable((By.ID, self.passwordId)))
        pwdElement.send_keys(password)
        wait.until(lambda d: pwdElement.get_attribute("value") == password)
        sleep(2)
        inloggenButton = wait.until(EC.element_to_be_clickable((By.ID, self.inloggenButtonId)))
        inloggenButton.click()
        GeneralPage(self.driver).logged_on()