简体   繁体   English

如何在 python 中的 selenium 中获取此特定元素

[英]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 从netlifyeasybase获取我的统计信息。 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.

相关问题 如何在python中使用selenium选择具有特定`title`的元素 - How can I select an element with a specific `title` using selenium in python 我如何单击 selenium python 中列表的特定类别元素 - How can i click specific category element of list in selenium python 如何在 Python 中使用 Selenium 来获取 JavaScript 元素? - How can I use Selenium in Python to get JavaScript element? 如何使用 selenium python 定位元素并获取编号 - how can i locate element and get the number by use selenium python Python & Selenium:如何从特定 div 中获取 href 元素? 我的元素是陈旧的 - Python & Selenium: How can I obtain a href element from a specific div? My element is stale 当页面上有这么多元素时,我如何 select 页面上的特定元素? Selenium webdriver python; - How can I select a specific element on a page when there is so many of that element? Selenium webdriver python; 如何在 Python Selenium 中找到这个元素 - How do I get to this element in Python Selenium 我如何从 python 字典中获取特定的元素和键 - How can i get specific Element and key from python Dictionary 如何使用python获取json中的特定元素 - how can I get a specific element in json with python Python selenium,如何删除元素? - Python selenium, how can i delete an element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM