Reputation: 11
I attempted to retrieve an tag using its classname from a webpage using Selenium.
I wrote the following:
import os
from selenium import webdriver
def launchBrowser():
os.environ['PATH'] += r"/SeleniumDrivers/chromedriver_mac_arm64"
driver = webdriver.Chrome()
#driver.implicitly_wait(15)
driver.get("https://www.geeksforgeeks.org/find_element_by_id-driver-method-selenium-python/")
element = driver.find_element("class_name", "header-main_wrapper")
#element = driver.find_element_by_xpath("//div[@class=bp3-button bp3-minimal]")
#link = element.get_attribute("href")
#link.click()
while(True):
pass
launchBrowser()
After debugging element = driver.find_element("class_name", "header-main_wrapper")
returns the error above. I'm unsure why. I think I followed the method signature properly which is why I'm unsure what I'm doing wrong.
Upvotes: 0
Views: 343
Reputation: 8508
Change the below line:
element = driver.find_element("class_name", "header-main_wrapper")
To:
element = driver.find_element(By.CLASS_NAME, "header-main_wrapper")
Imports required:
from selenium.webdriver.common.by import By
Upvotes: 1