Webdriver可以登录Chrome,而不是在Firefox中:“无法找到拥有的文档”错误 [英] Webdriver can login in Chrome, not in firefox: 'Unable to find owning document' error
问题描述
我将相同的代码复制到B类中,并将浏览器实例更改为firefox,同时仍将drive驱动程序声明为public static。 Firefox已启动,已打开网址,输入用户名和密码,但登录按钮未点击或提交。测试失败,出现错误:
org.openqa.selenium.JavascriptException:错误:无法找到拥有的文档。
我从来没有遇到这个错误,不知道拥有文档是被引用的。我怀疑它与一个或两个类的访问级别有关。以下是2类的摘录。我错过了什么吗?
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheChrome {
public static WebDriver驱动程序;
@BeforeClass(alwaysRun = true)
public void launchBrowser(){
driver = new ChromeDriver();
driver.get(http://www.example.com);
driver.manage()。window()。maximize();
@Test
public void verifyLogin()throws InterruptedException {
driver.findElement(By.id(username))。sendKeys(user) ;
driver.findElement(By.id(password))。sendKeys(password);
Thread.sleep(3000);
driver.findElement(By.id(loginButton))。click();
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheFirefox {
public static WebDriver驱动程序;
@BeforeClass(alwaysRun = true)
public void launchBrowser()throws InterruptedException {
driver = new FirefoxDriver();
driver.get(http://www.example.com);
driver.manage()。window()。maximize();
Thread.sleep(3000);
}
@Test
public void verifyLogin()throws InterruptedException {
driver.findElement(By.id(username ))的SendKeys( 用户)。
driver.findElement(By.id(password))。sendKeys(password);
Thread.sleep(3000);
driver.findElement(By.id(loginButton))。click();
这是使用Firefox版本引起的问题,49.0.2。这是一个奇怪的情况,不清楚为什么使用浏览器版本传递登录功能;但是,解决该问题需要降级到46.0版本。这解决了问题。
I have 2 classes belonging to the same package in a java testNG project and I have declared 'webdriver driver' public static in class A. In that class, chrome launched, url opened, username and password were entered and login button clicked. Worked fine using @BeforeClass annotation.
I copied the same code into a class B and changed browser instance to firefox whilst still declaring 'webdriver driver as public static. Firefox Launched, URL opened, username and password were entered but login button did not click or submit. Test failed with the error:
org.openqa.selenium.JavascriptException: Error: Unable to find owning document.
I have never come across this error and have no idea what 'owning document' is being referred to.I am suspecting it has something to do with the access level for either or both classes. Below is an extract from the 2 classes. Am I missing something?
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheChrome {
public static WebDriver driver;
@BeforeClass(alwaysRun = true)
public void launchBrowser() {
driver = new ChromeDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
@Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheFirefox {
public static WebDriver driver;
@BeforeClass(alwaysRun = true)
public void launchBrowser() throws InterruptedException {
driver = new FirefoxDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
Thread.sleep(3000);
}
@Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
This is an issue caused by the Firefox version in use, 49.0.2. It's a weird case and unclear why login functionality is being imparted by the browser version in use;however, resolving the issue requires a downgrade to version 46.0. This fixed the problem.
这篇关于Webdriver可以登录Chrome,而不是在Firefox中:“无法找到拥有的文档”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!