简体   繁体   English

无法在输入密码字段中输入密码 Selenium

[英]Can't Input Password into input password field Selenium

I can input my username but I cannot input the password for this website.我可以输入我的用户名,但我不能输入这个网站的密码。 Even when I try waiting for the field to become clickable it does not work.即使我尝试等待该字段变为可点击,它也不起作用。

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

url =  'https://sso.accounts.dowjones.com/login?state=g6Fo2SBPMzZrekJkSlJDUWhfdHRaYmFMQXFzXzFSd2hFV01BMqN0aWTZIEVaQkVtc2FWT0Rkak1ENVl5Q21JeEM1Z3RhWWZZSUY4o2NpZNkgNWhzc0VBZE15MG1KVElDbkpOdkM5VFhFdzNWYTdqZk8&client=5hssEAdMy0mJTICnJNvC9TXEw3Va7jfO&protocol=oauth2&scope=openid%20idp_id%20roles%20email%20given_name%20family_name%20djid%20djUsername%20djStatus%20trackid%20tags%20prts%20suuid%20createTimestamp&response_type=code&redirect_uri=https%3A%2F%2Faccounts.barrons.com%2Fauth%2Fsso%2Flogin&nonce=fd1626cc-b81b-4b33-bb37-6795e64b26d3&ui_locales=en-us-x-barrons-81-2&ns=prod%2Faccounts-barrons#!/signin-password'
        driver = webdriver.Firefox()
        driver.get(url)

        WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[class="username"'))).send_keys("email")
        #WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'continue-submit'))).click()
        time.sleep(10)
        #WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'basic-login-submit'))).click()
        WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[class="password"'))).send_keys("password")
        WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'basic-login-submit'))).click()
  

The error I get is a timeouterror because it can't send keys to it.我得到的错误是超时错误,因为它无法向它发送密钥。 My main questions are:我的主要问题是:

  1. How do you fix this?你如何解决这个问题?
  2. Why does the User field work but not the Password field为什么用户字段有效但密码字段无效

I have had similar issues in the past that have been solved by clicking the element first and THEN finding the element to click.过去我遇到过类似的问题,通过先单击元素然后找到要单击的元素来解决这些问题。 I believe that some websites change the HTML slightly after the element is clicked or "focused", so the element may have to be found again.我相信有些网站在元素被点击或“聚焦”后会稍微更改 HTML,因此可能需要再次找到该元素。

Some websites also have the ability to detect scripts like this.一些网站也有能力检测这样的脚本。 You may want to try adding a delay in between each key.您可能想尝试在每个键之间添加延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM