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
IE能跑是因为你的系统是win,它会寻找你的默认安装路径,而你的firefox和chrome非默认路径安装,你可以指定安装路径试试。希望对你有所帮助 StringbrowserType="*firefox 路径";
这个应该是需要把火狐和google添加到环境变量path里.回复 @红鼠:对啊,把exe格式的那个路径放上去,我的是这样的D:\ProgramFiles\MozillaFirefox\;怎么配?把他的安装路径配到PATH中去?版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。