![]()
问题如下:
代码如下:
包TestNG1;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.support.FindBy;
导入org.openqa.selenium.support.PageFactory;
导入org.testng.annotations.Test;
公共类TestDemo1 {
@FindBy(id =“ u”)
公共WebElement用户名;
@FindBy(id =“ p”)
WebElement公共密码;
@FindBy(id =“ login_button”)

公共WebElement登录按钮;
公共TestDemo1(WebDriver驱动程序){
PageFactory.initElements(驱动程序qq邮箱登录手机版网页,此);
}
}
包TestNG1;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.testng.annotations.BeforeMethod;
导入org.testng.annotations.Test;
公共类TestDemo2 {
WebDriver dr;

字符串url =“ https://en.mail.qq.com/cgi-bin/loginpage”;
@BeforeMethod
public void BeforeMethod(){
System.setProperty(“ webdriver.firefox.bin”,“ D: \\程序文件\\ firefox \\ firefox.exe”);
dr =新的FirefoxDriver();
dr.get(url);
dr.manage(). 视窗(). 最大化();
}
@测试
公共无效f(){
TestDemo1测试=新的TestDemo1(博士);
test.Username.sendKeys(“ XXXXXX”);
test.Password.sendKeys(“ XXXXXX”);
test.Loginbutton.click();

}
}
页面错误:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"u"}
修改为:
包TestNG1;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.testng.annotations.BeforeMethod;
导入org.testng.annotations.Test;
公共类TestDemo2 {
WebDriver dr;
字符串url =“ https://en.mail.qq.com/cgi-bin/loginpage”;
![]()
@BeforeMethod
public void BeforeMethod(){
System.setProperty(“ webdriver.firefox.bin”,“ D: \\程序文件\\ firefox \\ firefox.exe”);
dr =新的FirefoxDriver();
dr.get(url);
dr.manage(). 视窗(). 最大化();
}
@测试
公共无效f(){
WebElement frame = dr.findElement(By.id(“ login_frame”)); //添加框架元素
dr.switchTo(). 帧(帧);
TestDemo1测试=新的TestDemo1(博士);
test.Username.sendKeys(“ XXXXXXX”);
test.Password.sendKeys(“ XXXXXXX”);
test.Loginbutton.click();
}
}
原因: 由于元素包含在框架中qq邮箱登录手机版网页,因此您需要在找到元素之前添加go to frame语句.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-145196-1.html
11111111111
它已超出了双边或多边的范畴