在Eclipse中运行代码时,弹出窗口显示为“无法启动”

时间:2017-02-06 17:26:42

标签: java selenium

我已经尝试了下面的代码,在运行代码时我得到的弹出窗口是“选择无法启动且没有最近的启动”

请你帮助我....

由于

完整代码:

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 {

/**

    @param args

*/

public static void main(String[] args) {

// objects and variables instantiation

WebDriver driver = new FirefoxDriver();

String appUrl = "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";

// 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);

}

}

1 个答案:

答案 0 :(得分:0)

我执行了你分享的代码。它没有抛出你提到的错误。我对您的代码所做的唯一更改是设置系统属性 webdriver.gecko.driver ,因为我使用的是最新的Selenium库,并且需要设置此路径以使用Firefox。我也建议您使用最新的Selenium library。您可以从here下载 geckodriver

在初始化 FirefoxDriver 对象之前,您需要设置相关的系统属性。您可以通过以下方式执行此操作:

System.setProperty("webdriver.gecko.driver", "<path_to_geckodriver.exe>");
WebDriver driver = new FirefoxDriver();

如果您有任何疑问,请与我们联系。