How can I get this SPECIFIC element in selenium in python

Viewed 42

UPDATE: So thanks to the voted answer it displayed some information not the right information, it shows 0kb out of 100 and when in the inspect element console if doing console.log($0) then the item would be displayed in console how do I fetch this

I want to create a python 3.x programme that gets my stats off of netlify and easybase using selenium. The issue I have come across already is that the element does not have a specific class name and the text widget isn't just a

tag nor a tag. Here is a screenshot of the html of netlify the screenshot, and this is the code that I used

element = driver.find_element_by_name("github")
element.click()
login = driver.find_element_by_name("login")
login.send_keys(email)
password = driver.find_element_by_name("password")
password.send_keys(passwordstr)
loginbtn = driver.find_element_by_name("commit")
loginbtn.click()
getbandwidth = driver.find_element_by_xpath('//*[@id="main"]/div/div[1]/div/section/div/div/div/dl/div/dd')
print(getbandwidth.text)

1 Answers
getbandwidth = driver.find_element_by_xpath("//dd[@class='tw-text-xl tw-mt-4px tw-leading-none']")

You can use this to grab the first xpath with that class. Below does the same but if you want to index other elements with similar classes.

(//dd[@class='tw-text-xl tw-mt-4px tw-leading-none'])[1]

Normally we use webdriver waits to allow for the element to become visible.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
getbandwidth = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,"//dd[@class='tw-text-xl tw-mt-4px tw-leading-none']")))
Related