0

I've written web scraping scripts that worked in the past however I'm running into something new that I can't figure out on TradingView. There are buttons in the chart that don't seem like buttons, at least the code is not able to press it. I've attached the code from one of these buttons.

<div class="control-bar control-bar__btn control-bar__btn--back-present apply-common-tooltip control-bar__btn--btn-hidden" style="bottom: 33px; margin-right: 72px;" xpath="1">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" width="14" height="14"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6.5 1.5l5 5.5-5 5.5M3 4l2.5 3L3 10"></path></svg>
</div>

I've taken a screenshot also as Firefox shows event and flex in the code which I'm sure is relevant.

enter image description here

Using

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

doesn't work. I also tried using CSS. Any help is greatly appreciated.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
vulcan4d
  • 1
  • 1

1 Answers1

0

To click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.control-bar.control-bar__btn.control-bar__btn--back-present.apply-common-tooltip > svg"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'control-bar control-bar__btn control-bar__btn--back-present apply-common-tooltip')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217