为什么“browser.find_element_by_id”在我的代码中不起作用?

时间:2017-05-02 10:45:37

标签: python popup find element flyout

请任何人解释为什么我的代码在下面失败了:

emailElem = browser.find_element_by_id(“loginemail”)

? 直到大约2周前,它运作良好。请注意, loginid passwordid 只是任意登录详细信息,应在弹出屏幕中输入。

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

def login():
#
    binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')
    browser = webdriver.Firefox(firefox_binary=binary)
#
    browser.get('https://purpleport.com/login.asp')
    time.sleep(10)
    window_main = browser.window_handles[0]
    emailtext = 'loginid'
    pwdtext = 'passwordid'
#
    emailElem = browser.find_element_by_id("loginemail")
    emailElem.send_keys(emailtext)
    passwordElem = browser.find_element_by_id("loginpassword")
    passwordElem.send_keys(pwdtext)
    passwordElem.send_keys(Keys.ENTER)
#
    browser.switch_to.window(window_main)
#
    time.sleep(10)
    main_window = browser.current_window_handle
#
    return browser
#
login()

0 个答案:

没有答案