[英]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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.