簡體   English   中英

Webdriver selenium - 在 TradingView 中找不到任何元素

[英]Webdriver selenium - can't find any element from TradingView

我是使用 Selenium 的新手,但我觀看了足夠多的視頻並關注了足夠多的文章,知道缺少一些東西。 我正在嘗試從 TradingView 獲取值,但我遇到的問題是我根本找不到任何元素,而不是 Xpath 或 Css。 我繼續嘗試做一個簡單的可見性元素測試,如下面的代碼所示,令我驚訝的是它超時了。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
# Stops the UI interface (chrome browser) from popping up
# chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path='c:\se\chromedriver.exe', options=chrome_options)

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time

driver.get("https://www.tradingview.com/chart/")

timeout = 20
try:
    WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[1]")))
    print("Page loaded")
except TimeoutException:
    print("Timed out waiting for page to load")
driver.quit()

我也嘗試使用以下方法單擊圖表按鈕之一,但這也不起作用。 我注意到,與 Tradingview 的許多其他網站不同,這些元素沒有名稱,也沒有使用 Xpath 生成相對路徑(僅完整)。

driver.find.element_by_xpath('/html/body/div[2]/div[5]/div/div[2]/div/div/div/div/div[4]').click()

任何幫助是極大的贊賞!

我認為 xpath 一定有問題。 當我嘗試單擊 AAPL 按鈕時,它對我有用。 我使用的xpath是:

(//div[contains(text(),'AAPL')])[1]

如果您確切指定要單擊的元素,我會嘗試。 並且還要熟悉框架的概念,因為這些類型的網站中有很多框架。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM