Selenium webdriver Selenium Webdriver中的编译错误:字段package.Classfile.driver不可见
我似乎遇到了某种编译错误 我在“base”包中有“Common.java”类。这是一个启动firefox驱动程序的程序。因此,我将其保存在单独的包中,以实现一次性工作和模块化 我在子类“tc_01.java”中调用这个类文件。该TC_01.jave程序在另一个“测试”包中。这个TC_01.java文件实际上是从Common.java访问驱动程序,启动浏览器并尝试一些登录和注销操作 我的子类TC_01.java向我显示编译错误,鼠标悬停时的错误消息是–>“field Common.driver不可见”。 在控制台:“java.lang.Error:未解决的编译问题: 字段Common.driver不可见“ 我的分析:TC_01.java文件似乎无法从“Common.java”访问“driver”。 但是,我已经为它编写了“extends”关键字来继承属性 请引导我。谢谢 这是我的代码:->Selenium webdriver Selenium Webdriver中的编译错误:字段package.Classfile.driver不可见,selenium-webdriver,Selenium Webdriver,我似乎遇到了某种编译错误 我在“base”包中有“Common.java”类。这是一个启动firefox驱动程序的程序。因此,我将其保存在单独的包中,以实现一次性工作和模块化 我在子类“tc_01.java”中调用这个类文件。该TC_01.jave程序在另一个“测试”包中。这个TC_01.java文件实际上是从Common.java访问驱动程序,启动浏览器并尝试一些登录和注销操作 我的子类TC_01.java向我显示编译错误,鼠标悬停时的错误消息是–>“field Common.driver不可
package base;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class Common {
public FirefoxDriver driver;
@BeforeMethod
public void BM(){
System.setProperty(“webdriver.gecko.driver”,”D://Rajiv//Selenium//geckodriver.exe”);
driver = new FirefoxDriver();
driver.get(“http://automationpractice.com/index.php”);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterMethod
public void CM(){
driver.close();
}
}
# Pakage – testing; Class – Tc_01.java
package testing;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import base.Common;
public class TC_01 extends Common{
public FirefoxDriver driver;`
@Test
public void TM(){
System.out.println(“Selenium Webdriver Script in Firefox browser using Gecko` `Driver | AutomationPractice.com PAGE LAUNCHED”);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“search_query_top”)));
try{
String expectedTitle = “My Store”;
System.out.println(“ExpectedTile = “+expectedTitle );
String actualTitle = driver.getTitle();
System.out.println(“The actual Title of the Page is = “+actualTitle);
Assert.assertEquals(actualTitle, expectedTitle);*/
System.out.println(“Control has reached here”);
driver.findElementByClassName(“login”).click(); // field common.driver is not visible
driver.findElementById(“email”).sendKeys(“*****@yahoo.com”);
driver.findElementById(“passwd”).sendKeys(“*****”);
driver.findElementById(“SubmitLogin”).click();
driver.findElementByClassName(“logout”).click();
System.out.println(“Sucessfully Logout from the Application”);
}catch (Exception e){
e.printStackTrace();
}
}
}
我找到了这个问题的根本原因。 我浪费了三天时间才在这个论坛上寻求帮助。 正如我最初分析的那样,我在父类中提到了我的驱动程序属性,并在子类中访问它。有一些名称不匹配。当它试图从父级继承属性时,它不可访问,并且给了我编译错误。我将父类名称重命名为在子类中扩展时提供的名称。而且,它起了作用。 再次感谢大家。这是一个非常好的论坛,可以在彼此之间讨论你们的问题并得到解决