使用 python 在 Tradingview 图表中向右滚动

Scroll to right in Tradingview chart using python

我正在尝试在 TradingView

中使用 selenium python 向右滚动

我的代码:

driver.find_element_by_xpath("//div[@class='control-bar__btn control-bar__btn--move-right apply-common-tooltip']").click()

它抛出一个错误:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

首次加载页面时会显示一条消息 window。如果你不这样做,你必须先关闭它(让右箭头容器可见)

driver.findElement(By.xpath(".//span[包含(@class,'closeIcon')]")).click();

driver.findElement(By.xpath(".//td[@class='chart-markup-table time-axis']")).click();//获取正确箭头容器可见

driver.findElement(By.xpath(".//div[@class='control-bar__btn control-bar__btn--move-right apply-common-tooltip']").click();

试试下面的代码-

import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
wait = WebDriverWait(driver, 60)
action = ActionChains(driver)

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

try:
    wait.until(EC.visibility_of_element_located((By.XPATH, "//span[contains(@class,\"closeIcon\")]"))).click()
except:
    pass

RightScroll = wait.until(EC.presence_of_element_located((By.XPATH,"//div[contains(@class,\"btn--move-right\")]")))

for i in range(10):
    time.sleep(2)
    print(i)
    action.move_to_element(RightScroll).click().perform()

如果解决了您的问题,请标记为答案。如果您有任何疑问,请告诉我。