开发者社区> 问答> 正文

selenimu 在FF,及chrome运行报错,IE下运行正常?报错

 public static void main(String[] args)
  {
   String host = "localhost";
   int port = 4444;
   String url = "http://www.baidu.com/";
   String browserType = "*firefox";
 
   String keyWordsLocator = "document.getElementById('kw')";  
   String search = "document.getElementById('su')";
   DefaultSelenium selenium = new DefaultSelenium(host,port,browserType,url);
   selenium.start();
   selenium.open(url);
   selenium.type(keyWordsLocator,"java selenium");
   selenium.click(search);
   selenium.waitForPageToLoad("50000");
   selenium.stop();
  System.out.println("..............");
  }

browserType = "*firefox"; 改成*chrome也不行,改成iexplore则正常,报错如下:

Exception in thread "main" java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
 at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:109)
 at SeleniumDemo01.main(SeleniumDemo01.java:15)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Error while launching browser
 at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
 at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
 at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
 at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
 at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:100)
 ... 1 more

 

展开
收起
爱吃鱼的程序员 2020-06-22 22:13:16 442 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    IE能跑是因为你的系统是win,它会寻找你的默认安装路径,而你的firefox和chrome非默认路径安装,你可以指定安装路径试试。希望对你有所帮助 StringbrowserType="*firefox 路径";

    这个应该是需要把火狐和google添加到环境变量path里.回复 @红鼠:对啊,把exe格式的那个路径放上去,我的是这样的D:\ProgramFiles\MozillaFirefox\;怎么配?把他的安装路径配到PATH中去?
    2020-06-22 22:13:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载