Python 3.x Can';t使用selenium登录outlook

Python 3.x Can';t使用selenium登录outlook,python-3.x,Python 3.x,我正试图用python3这本书来解决自动化这个枯燥的实践项目 我被要求用selenium构建程序。它在哪里找到电子邮件输入和密码并将其分配到字段当我做所有这些时,我发现自己在点击提交按钮时遇到了困难,它给我selenium.common.exceptions.StaleElementReferenceException错误 以下是我所做的: #!/usr/bin/env python3 from selenium import webdriver url = 'https://login.li

我正试图用python3这本书来解决自动化这个枯燥的实践项目 我被要求用selenium构建程序。它在哪里找到电子邮件输入和密码并将其分配到字段当我做所有这些时,我发现自己在点击提交按钮时遇到了困难,它给我selenium.common.exceptions.StaleElementReferenceException错误 以下是我所做的:

#!/usr/bin/env python3
from selenium import webdriver

url = 'https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1617646022&rver=7.0.6737.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1%26RpsCsrfState%3da6d2e9e1-99f2-5a9e-6194-166e3842c959&id=292841&aadredir=1&CBCXT=out&lw=1&fl=dob%2cflname%2cwld&cobrandid=90015'

#login 

driver = webdriver.Firefox()

driver.get(url)

emailInput = driver.find_element_by_id('i0116')
emailInput.send_keys('email@hotmail.com')

submit = driver.find_element_by_id('idSIButton9')
passwordInput = driver.find_element_by_id('i0118')
passwordInput.send_keys('passwordsomthing')
submit.click()

我刚刚测试了这段代码,它运行正常。如果您有任何问题,请告诉我

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


firefox_options = Options()
firefox_options.add_argument("--test-type")
firefox_options.add_argument('--ignore-certificate-errors')
firefox_options.add_argument("--disable-infobars")
firefox_options.add_argument("--disable-extensions")
firefox_options.add_argument("--disable-popup-blocking")

driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver', options=firefox_options)

driver.get('https://login.live.com/')

username_box = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CSS_SELECTOR, '.input.text-box')))
username_box.send_keys('test@outlook.com')

driver.implicitly_wait(10)

next_button = driver.find_element_by_css_selector('.button.primary')
next_button.click()

password_box = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CSS_SELECTOR, '.input.text-box')))
password_box.send_keys('somepassword')

driver.implicitly_wait(10)

submit_button = driver.find_element_by_css_selector('.button.primary')
submit_button.click()

这是可行的,但这超出了我的理解atm@seprico我很高兴它对你有用。请接受解决您的问题的答案。