0

I want to ask aobut driver.find_element(). I want to make the automatic site login with a chrome driver and python. I want to click the login button, but it doesn't work.

Here is code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys       
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()     
driver.get('https://www.naver.com')
time.sleep(2)

search = driver.find_element(By.CLASS_NAME,'link_login')  
search.click()  

I also used

search = driver.find_element(By.CLASS_NAME,'link_login')

but it didn't work too. How can I make it to work?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

You were close. To click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CLASS_NAME:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "link_login"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.link_login"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='link_login']"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352