0

I am having a very difficult time clicking on the "Sign In" element at www.tradingview.com. I've inserted an implicitly_wait and have tried finding the element by xPath and class name. Regardless of what I try, I either get element not interactable or unable to locate element.

from selenium import webdriver

def sign_in():
    driver = webdriver.Chrome()
    driver.get('https://www.tradingview.com/')
    driver.implicitly_wait(10)
    driver.find_element_by_class_name('tv-header__profile-menu js-device-menu-btn').click()

sign_in()
1
  • @Emma unfort their API doesn't do what I need. Commented Sep 1, 2019 at 23:40

4 Answers 4

2

Seems that you are trying to find the wrong element...

Try this one:

driver.find_element_by_xpath("//a[text()='Sign In']/ancestor::span").click()
Sign up to request clarification or add additional context in comments.

4 Comments

I'm still getting the same unable to locate element error. Did that work for you?
@BorangeOrange1337 this page has some duplicated elements, try this one: driver.find_element_by_xpath("//a[text()='Sign In']/ancestor::span").click(), sorry for the first answer, I did not test it properly, this one was tested and clicked.
TYVM, really appreciate the help. I don't understand tho, how did you find this? Shouldn't inspecting the sign-in button work?
Hi @BorangeOrange1337, after some analysis on the html, you can see that we have duplicated elements, basically, it has two versions, one for mobile and other one for PC, on this page you have two 'Sign In' buttons, your locator was finding the mobile version that you cannot interact if you are not on the mobile version, if you shrink or browser or change it to mobile version, your old locator probably will work.
1

There are two sign ins. Target the second

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

def sign_in():
    driver = webdriver.Chrome()
    driver.get('https://www.tradingview.com/')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.tv-header__dropdown-text [href*=signin]'))).click()
sign_in()

If all else fails you can use javascript to click

driver.execute_script("document.querySelector('[href*=signin]').click();")

Comments

0

Hey try this once it will work

driver.findElement(By.Xpath("//span//a[text()='Sign In']")).click();

Comments

0
  1. If you change the locator strategy to XPath Selector your code will be more readable and understandable
  2. Consider using Explicit Wait as it's more flexible solution which saves time and CPU cycles.

Example code:

driver.get("https://www.tradingview.com/")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//a[text()='Sign In']"))).click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.