Search code examples
pythonseleniumauthenticationbuttontarget

Cannot target the element in Python - Selenium


I am starting with Python - Selenium and I cannot target the element in login website. I tried many options of targeting this button but no options works (class name, css selector, id, name..). When I skip this step and get on the next page manually by exact url the finding, focusing, sending keys to element and clicking on the "Next" button is no problem but this "welcome" login button cannot target totally. Using function "driver.find_element_by_XXX".

For example: "driver.find_element_by_class_name("login-box-actions").click()" Please, where I am making a mistake?

Many thanks, regards David

<div class="login-box-actions">
                    <a style="cursor: pointer" ng-click="confirmLogin()" class="btn btn-primary btn-block btn-flat ng-binding">Login</a>
                </div>

Solution

  • It may fail because the element could not found. For that, you have to wait for the element to be load and clickable.

    Refer to the following example, wait for the element to be clickable.

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, "btn btn-primary btn-block btn-flat ng-binding"))).click()