skip to Main Content

I am trying to click on a button which has the following html structure:

<button class="btn waves-effect waves-light">Login</button>

I would like to click the Login button, here is my code:

driver = webdriver.Chrome()
driver.get()
driver.find_element("link text", "Login")

the result is:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Login"}

can you please help me to figure it out? Many Thanks!

2

Answers


  1. from selenium import webdriver

    Initialize the WebDriver

    driver = webdriver.Chrome()

    Navigate to a URL

    driver.get("URL of the web page")

    Find the "Login" button by its class name

    login_button = driver.find_element_by_class_name("btn")

    Click the button

    login_button.click()

    Login or Signup to reply.
  2. in selenium4:

    from selenium.webdriver.common.by import By
    ...
    driver.find_element(By.Link_Text,'Login').click()
    

    not in selenium4:

    driver.find_element_by_link_text('Login').click()
    

    I hope it can help you!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search