The get_attribute() method in Python Selenium gives an error:
Did you mean 'getattribute'.
Why do I need that?
I am trying to get the parent elements class attribute to know if I got to the right DOM place.
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from datetime import datetime
#import pandas as pd
driver = webdriver.Chrome(r"C:\Users\Admin\Downloads\chromedriver_win32 (1)\chromedriver.exe")
driver.get("https://www.nba.com/schedule?pd=false®ion=1")
driver.implicitly_wait(5)
element_to_click = driver.find_element(By.ID, "onetrust-accept-btn-handler") #.click()
element_to_click.click()
element_to_save = driver.find_element(By.XPATH, "//div/div/div/div/h4")
#Element_to_save.to_excel("3row, 3column)")
f = open('result_file00.txt', 'r+')
f.write(element_to_save.text)
f.write("\n")
f.write(str(datetime.today()))
myList = []
myList.append(1)
elements_to_save = driver.find_elements(By.XPATH, "//*[@data-id='nba:schedule:main:team:link']")
for element in elements_to_save:
f.write(" ")
f.write(element.text)
myList.append(element.text)
f.write(" \n ")
f.write(str(datetime.today()))
f.close()
f = open('result_file00.txt', 'r+')
print(f.read())
f.close()
print(myList)
print(type(myList))
time.sleep(1)
driver.get("https://www.nba.com/stats/teams/traditional")
element_to_search = driver.find_element(By.LINK_TEXT, myList[1])
parentof_element_to_search = element_to_search.parent
print(parentof_element_to_search.get_attribute("class")) # Error-giving line
driver.quit()
I tried parentof_element_to_search = element_to_search.find_element(By.XPATH("..")) to get the parent element. Then trying to get the parent class of that element with parentof_element_to_search.get_attribute("class") resulted in the same error.
My desired code snippet from this result is getting the value of the 6-th <td> element in that <tr>.
find_element(By.XPATH("//td[6]"), the green line in the photo.
In brief, I get the team name's <td> line, then coming back to the same <tr> tag and getting 6 step for the <td> value.

site:stackoverflow.com get_attribute Selenium,getAttribute()in Java,get_attribute()in Python,GetAttribute()in C#,attribute()in Ruby,getAttribute()in JavaScript, andgetAttribute()in Kotlin...