[英]Selenium can't find class
I'm using Selenium with Python and I can't find the class depths: 我正在将Selenium与Python结合使用,但找不到类的深度:
element = browser.find_elements_by_xpath('.//span[@class = "depths"]')
or 要么
for a in browser.find_elements_by_class_name('depths')
from this link https://www.binance.com/trade.html?symbol=TRIG_BTC 从此链接https://www.binance.com/trade.html?symbol=TRIG_BTC
You can see the HTML with the class here: https://pastebin.com/CWEchN2f 您可以在此处查看带有类的HTML: https : //pastebin.com/CWEchN2f
I have more functions using Selenium in my code with another websites without any issue. 我在其他网站的代码中使用Selenium的功能更多,没有任何问题。
This is working code (Updated): 这是工作代码(已更新):
from selenium import webdriver
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
browser.get("https://www.binance.com/trade.html?symbol=TRIG_BTC")
elements = ui.WebDriverWait(browser, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".depths")))
print(elements)
Output: 输出:
[<selenium.webdriver.remote.webelement.WebElement (session="08e1be69e2b4b7eff2d76c4b8420a287", element="0.8669087765654466-1")>,
<selenium.webdriver.remote.webelement.WebElement (session="08e1be69e2b4b7eff2d76c4b8420a287", element="0.8669087765654466-2")>]
You have 2 elements with such class (here is JavaScript code for checking): 您有2个带有此类的元素(此处是用于检查的JavaScript代码):
Then access separate element in the loop or by index in the list (elements). 然后在循环中或通过列表中的索引访问单独的元素(元素)。
Hope it helps you! 希望对您有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.