localhost
localhost

Reputation: 603

How to get the "element name" for selenium?

I have (found) a python script whose purpose is to click a certain button on a certain web page. This is the script:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
url = "https://url"
driver.get(url)
button = driver.find_element_by_class_name("name-of-the-button")
button.click()

As I understand, "class name" is the name of the button. My question is how do I know the class name of the specific button on that specific website? What's the proper way to get this information from?

Upvotes: 0

Views: 47

Answers (1)

Blupper
Blupper

Reputation: 408

What you're looking for is called the developer tools. If you're using Chrome, here's a good tutorial. Most browsers have a very similar layout.

Essentialy you want to hit F12 to open up the developer tools, hit CTRL+SHIFT+C and click the button you want. On the right, the button source code should be highlighted, and you should be able to see a class= attribute.

Upvotes: 1

Related Questions