Search code examples
pythonseleniumselenium-webdriverwebdriverwaitwindow-handles

Using Selenium to Sign Into TradingView.com


I'm trying to use Selenium to sign into TradingView, but it appears as though selenium isn't able to find the password field and send keys, though I can see in real time the cursor click into the password field. I've even tried to send keys using ActionChains. I'm getting the following error:

AttributeError: 'NoneType' object has no attribute 'send_keys'

Below is my code. Any help is greatly appreciated!

from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

def get_data(self):
    driver = webdriver.Chrome(ChromeDriverManager().install())
    driver.get("https://www.tradingview.com/#signin")
    driver.find_element_by_xpath('//*[@title="Linked In"]').click()
    
    # Switch to new window
    window_after = driver.window_handles[1]
    driver.switch_to.window(window_after)

    # Click into password field, send password
    element = driver.find_elements_by_class_name("form__input--floating")[1].click()
    element.send_keys("TestPassword")

Solution

  • This error message...

    AttributeError: 'NoneType' object has no attribute 'send_keys'
    

    ...implies that your program is trying to invoke click() on a NoneType object.

    click() doesn't returns anything. So element remains NoneType object. Hence you see the error.


    Solution

    To sign into TradingView website through linkedin credentials you have to:

    • Switch to the newly opened window

    • Induce WebDriverWait for the element_to_be_clickable()

    • You can use the following Locator Strategies:

      driver.get("https://www.tradingview.com/#signin")
      parent_window  = driver.current_window_handle
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@title='Linked In']"))).click()
      WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
      windows_after = driver.window_handles
      new_window = [x for x in windows_after if x != parent_window][0]
      driver.switch_to_window(new_window)
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='password']"))).send_keys("BorangeOrange1337")
      
    • Browser Snapshot:

    tradingview_linkedin_login