How find an specific element of page in Selenium python, because I can't find them

Viewed 40

I have tried all ways that I knew, but can't found elements "login" and "password". Could someone help me, please? I am tired... link: https://trading.finam.ru/

    from selenium import webdriver
    import traceback
    from time import sleep
    url = 'https://trading.finam.ru/'
    driver =         webdriver.Chrome(executable_path=r"C:\Users\Idensas\PycharmProjects\pythonProject\selenium\chromedriver.exe")
    driver.get(url)
    sleep(2)
    try:
        x = driver.find_element_by_xpath('//label[contains(text(),"Логин")]')
        x.send_keys('123')
    except Exception:
        traceback.print_exc()

    finally:
        driver.close()
        driver.quit()

The picture of that site

2 Answers

The following xpaths will work:
//input[@name='login']
//input[@name='password']

I see the site is loaded slowly so you must put some delay, preferably explicit wait there like:

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


wait.until(EC.visibility_of_element_located((By.XPATH, "//input[@name='login']")))

before trying to insert a texts there

Any website takes sometime to completely load and all the elements are visible to user. To check the time take taken by your website in different regions you run a check on https://gtmetrix.com/

You can use the simple sleep for few secs until the page is loaded

from selenium import webdriver
import time

driver=webdriver.Chrome(//chromedriver_path_in_your_local//)
driver.get("https://trading.finam.ru/")
time.sleep(5)

login=driver.find_element_by_xpath("//input[@name='login']")
password=driver.find_element_by_xpath("//input[@name='password']")
Related