[英]How can I get this SPECIFIC element in selenium in python
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更新:因此,多亏了投票的答案,它显示了一些信息而不是正确的信息,它显示了0kb out of 100
并且当在检查元素控制台中如果执行console.log($0)
那么该项目将显示在控制台中我如何获取这个
I want to create a python 3.x programme that gets my stats off of netlify and easybase using selenium.我想创建一个 python 3.x 程序,使用 selenium 从netlify和easybase获取我的统计信息。 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我已经遇到的问题是该元素没有特定的 class 名称,并且文本小部件不仅仅是
tag nor a tag.标签也不是标签。 Here is a screenshot of the html of netlify the screenshot , and this is the code that I used这是 netlify 的html的屏幕截图,这是我使用的代码
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)
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.您可以使用它来获取带有 class 的第一个 xpath。 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.通常我们使用 webdriver 等待来让元素变得可见。
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']")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.