Search code examples
pythonselenium-webdriverclicking

How to click special button with selenium in python?


I am trying to use selenium to click certain buttons within the bank of america simulator, but the buttons don't seem to ever click. No new link is reached, which is something I haven't encountered before.

https://message.bankofamerica.com/onlinebanking_demo/OLB_Simulator/

I want to click "Sign in options" and then click "Sign in: Recognized device"

I tried using selenium to click the button and I get no error. Nothing happens at all and the program continues, so I know it's not an issue with not finding the button. My current code is as follows:

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get('https://message.bankofamerica.com/onlinebanking_demo/OLB_Simulator/')

sleep(3)

login_button = driver.find_element("id", "landing_sign")
driver.execute_script("arguments[0].click();", login_button);

Solution

  • This code worked fine for me.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
    driver.get('https://message.bankofamerica.com/onlinebanking_demo/OLB_Simulator/')
    wait = WebDriverWait(driver, 10)
    wait.until(EC.element_to_be_clickable((By.ID, "landing_sign")).click()
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[aria-labelledby='signInOpt3']")).click()
    

    NOTE: Using sleep is a bad practice, use WebDriverWait and wait for the specific state you need instead.