python-3.x - 如何在 Selenium python 中找到页面的特定元素,因为我找不到它们

标签 python-3.x selenium selenium-webdriver

我已经尝试了所有我知道的方法,但找不到元素“登录”和“密码”。有人可以帮我吗?我累了... 链接: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

最佳答案

以下xpath将起作用:
//输入[@name='login']
//输入[@name='password']

我发现该网站加载缓慢,因此您必须延迟一些,最好是明确等待,例如:

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']")))

在尝试插入文本之前

关于python-3.x - 如何在 Selenium python 中找到页面的特定元素,因为我找不到它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67267524/

相关文章:

python - 将字典展开到 DataFrame 中,然后添加到原始 DataFrame 中,并添加新列和复制的原始数据

python - 没有名为 'scipy.sparse._sparsetools' 的模块

c - 将 Selenium 与 C 结合使用

python - 使用 Selenium 单击 'Load More' 按钮直到它不存在(Youtube)

java - WebDriverException : It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream 和 long 未找到

ruby - 将隐式等待和显式等待结合在一起会导致意外的等待时间

python - 如何使用noise.py模块选择种子

python - pformat() 输出的缩进

python - Selenium:动态加载页面导致自动滚动失败

java - 需要在 selenium webdriver 代码中使用代理捕获网络流量