我使用下面的代码启动firefox浏览器但是收到错误

时间:2016-05-19 06:56:05

标签: java selenium firefox selenium-webdriver

我正在使用以下代码启动firefox浏览器,但我收到的错误如下。请帮我解决这个问题。

代码:

public class FirstClass {
    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver(); 

        try {
            driver.wait(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
        driver.get("www.Google.com");
        driver.close();
    }
}

错误:

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Bad request

Command duration or timeout: 5.81 seconds

Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'

System info: host: 'ATUMKURX-MOBL', ip: '10.223.181.206', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_74'

Driver info: org.openqa.selenium.firefox.FirefoxDriver

主机文件的内容:

localhost name resolution is handled within DNS itself.

127.0.0.1       localhost

::1             localhost

127.0.0.1       LIUYUNKX-MOBL.gar.corp.intel.com # LMS GENERATED LINE

4 个答案:

答案 0 :(得分:0)

试试这个

WebDriver driver = new FirefoxDriver()
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://www.google.com");
driver.close();

答案 1 :(得分:0)

而不是driver.wait(5000);使用Thread.sleep(5000);

下面的代码对我有用: -

  try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
    driver.get("www.Google.com");
    driver.close();
    System.out.println("Edd");

}

虽然不推荐使用Thread,但您也可以使用hiddenlyWait: -

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

隐式等待每个元素selenium寻找

等待你的脚本

希望它会对你有所帮助:)。

答案 2 :(得分:0)

WebDriver driver = new FirefoxDriver()
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.google.com");
driver.quit();

if same issue exits, please upgrade selenium jar (http://www.seleniumhq.org/download/) to latest, and updat`enter code here`e firefox to latest and try.. 

答案 3 :(得分:0)

以下是答案:

未评论主机文件的最后一行。

在评论最后一行后问题得到解决。