1

I am trying to get all buttons from a website but it seems the Selenium syntax has changed without the docs being updated. I am trying to get the buttons from the website as follows:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
url = 'https://www.programiz.com/python-programming'
driver.get(url)
buttons = driver.find_element(by=By.TAG_NAME("button"))

However I get the following error:

TypeError: 'str' object is not callable

As mentioned the docs still say to use find_element_by_tag_name which is depreciated. Can someone help please. Thanks

2 Answers 2

3

find_element_by_* commands are depreciated now.

To find all the <button> elements you can use the following locator strategies:

  • Using tag_name:

    buttons = driver.find_elements(By.TAG_NAME, "button")
    
  • Using css_selector:

    buttons = driver.find_elements(By.CSS_SELECTOR, "button")
    
  • Using xpath:

    buttons = driver.find_elements(By.XPATH, "//button")
    
Sign up to request clarification or add additional context in comments.

Comments

1

Problem is with TAG_NAME it is just constant not a callable method, new usage by docs should be:

driver.find_element(By.TAG_NAME, 'button') 

Checked docs here https://www.selenium.dev/selenium/docs/api/py/index.html#example-1

Comments

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.