Selenium-该方法未定义类型类。 Java类扩展期间的异常

时间:2017-01-31 10:56:46

标签: java selenium selenium-webdriver interface

我是seleniumjava的新手,并尝试构建一个程序并面临多个问题。列出的是以下父类的代码。

登录方法错误。

  

Void是令牌上的语法错误的有效类型错误"("。

即使我试图改变,我仍然面临错误

package MyfirstMavenProject.Myfirstgmailtest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginClass {

    //Open the Browser
    public  void BrowserOpen (String args[]) {

        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();

    //Get the URL   
    driver.navigate().to("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //Identifies the gmail and password
    public void  Login (String args[]) {

    WebElement emailfield = driver.findElement(By.id("Email")); 
    emailfield.sendKeys("abc.com");
        driver.findElement(By.id("next")).click();      
        WebDriverWait wait = new WebDriverWait(driver,30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@type='password']"))).sendKeys("abc");   
        driver.findElement(By.id("signIn")).click();    

    }
    }


}

Child Class是我在争论中遇到错误的地方。需要关于我应该通过什么参数的信息。我正在尝试使用在上面的类

中创建的Login方法
package MyfirstMavenProject.Myfirstgmailtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ComposeEmailClass extends LoginClass {

        //Method to identify the compose email
    public void ComposeEmail (String args[]){

        WebDriver ComposeEmail = new FirefoxDriver();       
        ComposeEmail.findElement(By.className("T-I J-J5-Ji T-I-KE L3")).click();
    }` public static void main  (String args[]){

     ComposeEmailClass ClickCompose = new ComposeEmailClass();
     ClickCompose.Login(args);`\\Need more info`
     ClickCompose.ComposeEmail(args);        
 }FireFox.Quit;
}

1 个答案:

答案 0 :(得分:0)

使用以下代码: 您的代码中存在许多语法错误。

登录类:已更正

package MyfirstMavenProject.Myfirstgmailtest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginClass 
{   
    WebDriver driver =null;
    //Open the Browser
    public  void BrowserOpen (String args[]) 
    {
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        //Get the URL   
        driver.navigate().to("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }

    //Identifies the gmail and password
    public  void Login (String args[])
    {

        WebElement emailfield = driver.findElement(By.id("Email")); 
        emailfield.sendKeys("youremail@gmail.com");
        driver.findElement(By.id("next")).click();      
        WebDriverWait wait = new WebDriverWait(driver,30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*    [@type='password']"))).sendKeys("password");   
        driver.findElement(By.id("signIn")).click();    
   }
}

ComposeEmailClass:已更正

package MyfirstMavenProject.Myfirstgmailtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

 public class ComposeEmailClass extends LoginClass 
 {

    //Method to identify the compose email
     public void ComposeEmail(String args[])
     {
        WebDriver ComposeEmail = new FirefoxDriver();       
        ComposeEmail.findElement(By.className("T-I J-J5-Ji T-I-KE L3")).click();
     } 
     public static void main(String args[])
     {
         ComposeEmailClass ClickCompose = new ComposeEmailClass();
         ClickCompose.BrowserOpen(args);
         ClickCompose.Login(args);
         ClickCompose.ComposeEmail(args);        
     }

}

您必须在ClickCompose.BrowserOpen(args);

之前致电ClickCompose.Login(args); 您的方法声明中不需要

String[] args