Locating & Clicking button (Selenium) Locating & Clicking button (Selenium) selenium selenium

Locating & Clicking button (Selenium)


The "by link text" locator would only work with links - a elements. Here you can use an XPath to check the text of the button:

driver.find_element_by_xpath("//button[. = 'Log out']").click()

As a side note, in this code:

elem = driver.find_element_by_link_text("Log out").click()

there is not much sense in assigning the result of click() to a variable - it'd always be None.