2016-10-18 1 views
-3

현재 Selenium 튜토리얼 Here을 사용하고 있으며 모든 단계를 정확하게 따라했지만 Eclipse 프로그램에서 오류가 계속 발생합니다. 이 튜토리얼은 이전 버전 용이지만 Selenium 3을 사용하고 있습니다. 이 튜토리얼을 제외하고는 포괄적 인 튜토리얼을 찾을 수 없습니다. 다음 코드에서 오류를 수정하려면 어떻게합니까? 나는 각 줄 이후에 얻은 정확한 오류에 대해 논평했다. 코드에는 이미 몇 개의 주석이 포함되어 있으므로 라인 시작 부분의 주석을 무시하십시오. 다른 모든 것은 오류 메시지 여야합니다.Selenium 튜토리얼 문제, 내가받는 오류를 어떻게 수정합니까?

Eclipse를 사용하여 클래스 경로를 설정하는 방법을 알아야하며 GeckoDriver에 액세스 할 수 있도록 허용해야합니다. GeckoDriver는이 문제를 해결할 수도 있고 그렇지 않을 수도 있습니다.

public class Gmail_Login { //Syntax error on token(s), misplaced construct(s) 
import org.openqa.selenium.By; //The import org.openqa.selenium.By cannot be resolved 
import org.openqa.selenium.WebDriver; // The import org.openqa.selenium.WebDriver cannot be resolved 
import org.openqa.selenium.WebElement;// The import org.openqa.selenium.WebElement cannot be resolved 
import org.openqa.selenium.firefox.FirefoxDriver;// The import org.openqa.selenium.firefox. cannot be resolved 

    /** 

    * @param args 

    */ 

      public static void main(String[] args) { //Multiple markers at this line -Syntax error,insert "enum Identifier" to complete EnumHeader -Syntax error on tokens, AnnotationName expected instead -Syntax error on token "}",invalid ( -Syntax error, insert")" to complete SingleMemberAnnotation -Syntax error, insert "]" to complete ArrayAccess 



    // objects and variables instantiation 

        WebDriver driver = new FirefoxDriver();//Multiple markers at this line -FirefoxDriver cannot be resolved to a type -WebDriver cannot be resolved to a type 

        String appUrl = "https://accounts.google.com"; 



    // launch the firefox browser and open the application url 

        driver.get(appUrl); 



    // maximize the browser window 

        driver.manage().window().maximize(); 



    // declare and initialize the variable to store the expected title of the webpage. 

        String expectedTitle = " Sign in - Google Accounts "; 



    // fetch the title of the web page and save it into a string variable 

        String actualTitle = driver.getTitle(); 



    // compare the expected title of the page with the actual title of the page and print the result 

        if (expectedTitle.equals(actualTitle)) 

        { 

         System.out.println("Verification Successful - The correct title is displayed on the web page."); 

        } 

       else 

        { 

         System.out.println("Verification Failed - An incorrect title is displayed on the web page."); 

        } 


    // enter a valid username in the email textbox 

        WebElement username = driver.findElement(By.id("Email"));//Multiple markers at this line -WebElement cannot be resolved to a type 

        username.clear(); 

        username.sendKeys("TestSelenium"); 


    // enter a valid password in the password textbox 

        WebElement password = driver.findElement(By.id("Passwd")); //Multiple markers at this line -WebElement cannot be resolved to a type -By cannot be resolved -By cannot be resolved  


        password.clear(); 
        password.sendKeys("password123"); 



    // click on the Sign in button 

        WebElement SignInButton = driver.findElement(By.id("signIn")); //Multiple markers at this line -WebElement cannot be resolved to a type  -By cannot be resolved 

        SignInButton.click(); 


    // close the web browser 

        driver.close(); 

        System.out.println("Test script executed successfully."); 


    // terminate the program 

        System.exit(0); 
      } 






}//Syntax error on token "}", delete this token 
+1

수업 외부로 가져 오지 않습니까? 자습서 에서처럼 다음과 같이 하시겠습니까? 또한, Selenium의 다른 버전을 목표로하기 때문에 모든 것이 동일하다고 무작위로 추측 할 수는 없습니다. –

+0

셀레늄 3는 아주 새로운 제품입니다. (5 일 전에 출시되었습니다). 철저한 튜토리얼이 아직 Selenium 3을 위해 작성되지 않았다고 확신 할 수 있습니다. – sircapsalot

+0

@DaveNewton 클래스 외부에 놓아도 동일한 오류가 모두 반환됩니다. 나는 그것들을 scope로 나중에 참조하기 쉽도록 클래스 밖에서 정의/가져 오기를 원한다고 생각했다. 셀레늄도 그 능력을 가지고 있는지 모르겠습니다. –

답변

0

나는 내가 한 모든 클래스의 외부에서 수입을 이동했다 하나 }를 삭제 오류가 도망 갔어요 생각합니다. 들여 쓰기를 수정하고 모든 오류 관련 주석을 제거했습니다. 이것을 시도하십시오 ...

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class Gmail_Login 
{ 
    public static void main(String[] args) 
    { 
     // objects and variables instantiation 
     WebDriver driver = new FirefoxDriver(); 
     String appUrl = "https://accounts.google.com"; 

     // launch the firefox browser and open the application url 
     driver.get(appUrl); 

     // maximize the browser window 
     driver.manage().window().maximize(); 

     // declare and initialize the variable to store the expected title of the webpage. 
     String expectedTitle = " Sign in - Google Accounts "; 

     // fetch the title of the web page and save it into a string variable 
     String actualTitle = driver.getTitle(); 

     // compare the expected title of the page with the actual title of the page and print the result 
     if (expectedTitle.equals(actualTitle)) 
     { 
      System.out.println("Verification Successful - The correct title is displayed on the web page."); 
     } 
     else 
     { 
      System.out.println("Verification Failed - An incorrect title is displayed on the web page."); 
     } 

     // enter a valid username in the email textbox 
     WebElement username = driver.findElement(By.id("Email")); 
     username.clear(); 
     username.sendKeys("TestSelenium"); 

     // enter a valid password in the password textbox 
     WebElement password = driver.findElement(By.id("Passwd")); 
     password.clear(); 
     password.sendKeys("password123"); 

     // click on the Sign in button 
     WebElement SignInButton = driver.findElement(By.id("signIn")); 
     SignInButton.click(); 

     // close the web browser 
     driver.close(); 
     System.out.println("Test script executed successfully."); 
     // terminate the program 
     System.exit(0); 
    } 
} 
+0

이것을 클라이언트에 복사/붙여 넣기하고 각각 패키지와 클래스의 이름을 변경했습니다. args가 문자열에 적용 가능하지 않다는 것을 말하는 .sendKeys()에 대한 오류가 발생합니다. –

+0

[이 페이지] (http://stackoverflow.com/questions/23485363/the-method-sendkeyscharsequence-in-the-type-webelement-is-not-applicable-for)에서 볼 수 있습니다. 정말 오래된 자바 버전인가요? 가장 최근의 JRE와 Selenium 버전이 설치되어 있는지 그리고 사용하고있는 다른 라이브러리가 있는지 확인합니다. – JeffC

+0

내 라이브러리가 최신 버전이었습니다. 필자의 컴파일러 준수를 1.7로 설정해야했습니다. –