简体   繁体   English

尝试登录时,Firefox的硒测试失败

[英]Selenium test fails with Firefox when trying to log in

We created extensions for Chrome, Firefox and Safari and we want to test our extensions with Selenium. 我们为Chrome,Firefox和Safari创建了扩展程序,并希望使用Selenium测试我们的扩展程序。 I created a test to log in to https://outlook.office365.com/owa/ and the test works with Chrome, but it fails with Firefox. 我创建了一个测试以登录到https://outlook.office365.com/owa/,并且该测试适用于Chrome,但对于Firefox而言则失败。 Also with Chrome I had to inject the JavaScript code directly into the page, because when clicking on the sign in button with Selenium nothing happens. 同样,在Chrome浏览器中,我不得不将JavaScript代码直接注入到页面中,因为当使用Selenium单击登录按钮时,什么也没有发生。 Do you know how I can log in to Office 365 with Firefox? 您知道我如何使用Firefox登录Office 365吗?

Here is my code: 这是我的代码:

import time
import unittest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

def login_to_office365(self, email, password, name):
    self.driver.maximize_window()
    self.driver.get(url='https://outlook.office365.com/owa/')
    self.assertEqual(first="Sign in to Office 365", second=self.driver.title)
    self.driver.find_element_by_xpath(xpath="//form[@id='credentials']//input[@name='login']").send_keys(email)
    self.driver.find_element_by_xpath(xpath="//form[@id='credentials']//input[@name='passwd']").send_keys(password)
    self.driver.find_element_by_xpath(xpath="//span[@id='cred_sign_in_button'][text()='Sign in']").click() # Nothing happens from this click.
    self.driver.execute_script("Post.SubmitCreds();") # Works only with Chrome.
    WebDriverWait(driver=self.driver, timeout=30).until(expected_conditions.title_is("{} - Outlook Web App".format(name)))
    self.assertEqual(first="{} - Outlook Web App".format(name), second=self.driver.title)

The exception is a timeout exception when waiting for the title to change. 当标题更改时,该异常是超时异常。

Following would work in c# *(python one is equivalent) 以下将在c#中工作*(python等效)

driver.FindElement(By.Id("username")).sendKeys(email);
driver.FindElement(By.Id("password")).sendKeys(password).submit();

Submit the form in a traditional way using submit() : 使用submit()以传统方式提交表单:

username_element = driver.find_element_by_id('username')
username_element.send_keys(email)

password_element = driver.find_element_by_id('password')
password_element.send_keys(password)

password_element.submit()

暂无
暂无

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

相关问题 测试失败时如何获取控制台日志 POSTMAN - How to get console log when the test fails POSTMAN Selenium firefox 21录制时无法log.debug,登录javascript时未显示任何内容 - Selenium firefox 21 cannot log.debug when recording, nothing showing up when logging in javascript Selenium-焦点和模糊在Firefox上随机失败 - Selenium - Focus and Blur fails randomly on Firefox 从具有Firefox扩展名的Selenium的Firefox 43中检索控制台日志 - Retrieving console log from Firefox 43 with Selenium without Firefox extensions 当运行硒测试时,Firefox窗口不清晰时,Onblur事件触发会陷入混乱 - Onblur event firing gets messed up when firefox window is not in focus while running a selenium test 量角器测试在Firefox上有效,但在Chrome上失败 - Protractor test works on Firefox but fails on Chrome 运行Selenium Webdriverjs测试时如何查看浏览器日志消息 - How can I see the browser log messages when running a selenium webdriverjs test 尝试使用JavaScript执行拖放操作进行Selenium WebDriver测试时出错 - Error when trying to execute drag and drop using javascript for Selenium WebDriver test 通过Selenium将密钥发送到Google Auth失败(使用Python和Firefox) - Sending keys via Selenium to Google Auth fails (using Python and Firefox) 尝试对其执行测试时,内置 Number 对象的覆盖方法失败 - Overwriting method of built-in Number object fails when trying to execute test on it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM