2015-10-05 112 views
1

我的代码是网址无法打开与webdriver的

package mentor.qa.selenium; 

import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

public class WDDemo1 { 

    public static void main(String[] args){ 
     WebDriver driver = new FirefoxDriver();   
     driver.get("http://www.google.com"); 
    } 
} 

我使用的是最新的Java jar文件2.47.1和Firefox 41.0.1。它启动Firefox,但不会去链接。我该如何解决这个问题?

+0

你有任何额外的错误消息,堆栈跟踪或日志? – Sebastian

+0

问题中有5个警告。构建路径指定执行环境javaSE-1.7。工作区中没有安装与此环境严格兼容的JRE。 –

+0

[Selenium WebDriver.get(url)可能的重复不会打开URL](http://stackoverflow.com/questions/7347494/selenium-webdriver-geturl-does-not-open-the-url) – Lucky

回答

0

代码正在工作,但优化了进口。

我用极小的编辑来运行你的代码。它打开谷歌网站。重新验证是否已经在构建路径中导入了selenium-java和selenium-server-standalone jar文件。

package com.jayant.selenium; 

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

public class SampleSelenium { 
    public static void main(String[] args){ 
     WebDriver driver = new FirefoxDriver(); 
     driver.get("http://www.google.com"); 
    } 
} 
-1

你的代码是完美的。这可能是配置问题,即使用相同代码的较低版本的Firefox。它会工作

+0

你有没有在较低的版本尝试它,或者它只是一个猜测? –

+0

我在Mozilla Firefox 38.0中使用了相同的代码,它工作正常 –

+0

这是一个日食问题,正如我在我的回答中提到的 –