我目前正在參加Selenium教程Here,我完全按照每一步操作,但是我的Eclipse程序一直在拋出錯誤。我正在使用Selenium 3,而本教程適用於舊版本。除此之外,我找不到任何全面的教程。如何修復以下代碼中的錯誤?我已經評論了每行後的確切錯誤。代碼已經包含了一些評論,所以在一行的開頭忽略任何評論。其他一切都應該是錯誤消息。硒教程麻煩,我如何解決我收到的許多錯誤?
我還需要知道如何使用Eclipse來設置我的類路徑,以允許它訪問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
不要進口到課外?就像你在學習的教程一樣?另外,由於您的目標是Selenium的不同版本,因此您可能無法隨機假設所有內容都是相同的。 –
硒3是非常新的。 (5天前發佈)。可以肯定的是,全面的教程還沒有被寫入Selenium 3 :) – sircapsalot
@DaveNewton即使當我把它們放在課堂外時,所有相同的錯誤也會返回。我的印象是,我想在課堂外定義/導入它們,以便稍後將它們引用到範圍中。我不確定Selenium是否有這種能力。 –