1

So I tried to click a button using selenium webdriver in Python. It didn't find the element (in this case a class name), even with enough time to load the element.

I got this error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".account-item login-btn waves-effect"}

here is my code:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://freecash.com")
time.sleep(3)

signIn = driver.find_element(By.CLASS_NAME, "account-item login-btn waves-effect")
signIn.click()

Please help me with this it would be greatly appreciated. If you need more info just ask down below. :)

1 Answer 1

1

To click on the element with text Sign In you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.execute("get", {'url': 'https://freecash.com'})
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.account-item.login-btn span"))).click()
    
  • Using XPATH:

    driver.execute("get", {'url': 'https://freecash.com'})
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='account-item login-btn waves-effect']//span[text()='Sign In']"))).click()
    
  • 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
    
Sign up to request clarification or add additional context in comments.

2 Comments

Wow, it works! Thank you very much. I tried using WebDriverWait earlier but it failed. I think I understand what I did wrong: seperating the waiting for element part from the finding the element part
Glad to be able to help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.