Selenium 无法访问登录页面

时间:2021-07-07 03:39:41

标签: python selenium selenium-webdriver

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


def main(driver):
    driver.get('https://account.t-mobile.com/signin/')
    waiter = WebDriverWait(driver, 30)

    try:
        waiter.until(EC.presence_of_element_located(
            (By.ID, 'usernameTextBox'))).send_keys("test@test.com")
        driver.find_element_by_id("lp1-next-btn").click()

    except TimeoutException as e:
        print(repr(e))


if __name__ == "__main__":
    options = Options()
    options.set_preference("dom.webdriver.enabled", False)
    driver = webdriver.Firefox(options=options)
    main(driver)

我无法登陆登录页面,因为它在使用 selenium 时会一直加载。

enter image description here

即使我尝试使用 Chrome 也会导致相同的情况。

1 个答案:

答案 0 :(得分:0)

看起来像 Firefox 表单应用程序端的一些问题。

我尝试切换到 chrome,它确实有效。

代码:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

executablePath= r'C:\\Users\\Desktop\\Selenium+Python\\chromedriver.exe'

def main(driver):
    driver.get('https://account.t-mobile.com/signin/')
    waiter = WebDriverWait(driver, 30)

    try:
        waiter.until(EC.presence_of_element_located(
            (By.ID, 'usernameTextBox'))).send_keys("test@test.com")
        driver.find_element_by_id("lp1-next-btn").click()

    except TimeoutException as e:
        print(repr(e))


if __name__ == "__main__":
    options = webdriver.ChromeOptions()
   # options.set_preference("dom.webdriver.enabled", False)
    driver = webdriver.Chrome(executable_path = executablePath, options=options)
    main(driver)

您可以从 official website here

获取最新的 chromedriver