selenium连接错误firebox java

时间:2018-02-26 07:00:22

标签: java selenium-webdriver

代码只是打开firefox,之后它没有打开给定的url。获取异常: - org.openqa.selenium.firefox.NotConnectedException:45000 ms后无法在端口7055上连接到主机127.0.0.1。 Firefox控制台输出:

代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class AzurePrice {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        int i=0,j=0;
        WebDriver driver = new FirefoxDriver();
        //driver.manage().deleteAllCookies();
        //Thread.sleep(5000L);
        driver.get("https://azure.microsoft.com/en-in/pricing/calculator/");
        driver.findElement(By.id("create-virtual-machines")).click();
        String[] options = driver.findElement(By.name("region")).getText().split("\n");
        //options.length;
        driver.findElement(By.name("region")).click();
        Select se = new Select((WebElement) driver);
        for(i=0;i<=options.length;i++)
        {
            se.selectByIndex(i);
            driver.findElement(By.name("operatingSystem")).click();
            se.selectByValue("windows");
            driver.findElement(By.name("type")).click();
            se.selectByValue("os-only");
            driver.findElement(By.name("tier")).click();
            se.selectByValue("standard");

            driver.findElement(By.id("radio-one-year-987a88d8-f8fa-4b6d-956a-7c0db87f3b92")).click();
            String[] options1 = driver.findElement(By.id("size")).getText().split("\n");
            for(j=0;j<options1.length;j++)
            {
                se.selectByIndex(j);
            }

        }
    }
}

2 个答案:

答案 0 :(得分:0)

您需要下载geckodriver.exe并设置system.property(),如下所示:

System.setProperty("webdriver.gecko.driver","path of geckdriver");

如果您使用的是最新版本的Selenium,则需要使用geckodriver。

答案 1 :(得分:0)

public class AzurePrice {
public WebDriver driver;
public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.gecko.driver","Your geckodriver path");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://azure.microsoft.com/en-in/pricing/calculator/");

    driver.findElement(By.id("create-virtual-machines")).click();

    String[] options = 
driver.findElement(By.name("region")).getText().split("\n");
    //options.length;
    driver.findElement(By.name("region")).click();
    Select se = new Select((WebElement) driver);
    int i=0,j=0;
    for(i=0;i<=options.length;i++)
    {
        se.selectByIndex(i);
        driver.findElement(By.name("operatingSystem")).click();
        se.selectByValue("windows");
        driver.findElement(By.name("type")).click();
        se.selectByValue("os-only");
        driver.findElement(By.name("tier")).click();
        se.selectByValue("standard");

        driver.findElement(By.id("radio-one-year-987a88d8-f8fa-4b6d-956a-7c0db87f3b92")).click();
        String[] options1 = driver.findElement(By.id("size")).getText().split("\n");
        for(j=0;j<options1.length;j++)
        {
            se.selectByIndex(j);
        }

    }
}

}