Selenium中常常会出现的问题

//因为Selenium默认的是firefox浏览器

import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Project1Class {
    public static void main(String[] args) {
        WebDriver driver = new InternetExplorerDriver();  

    }    
}

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
    at org.openqa.selenium.ie.InternetExplorerDriverService.access$0(InternetExplorerDriverService.java:1)
    at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
    at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:251)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
    at Project1Class.main(Project1Class.java:12)

应该改为:需要设置相应的浏览器的位置等等属性。
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Project1Class {
    public static void main(String[] args) {
        System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");  
        WebDriver driver = new InternetExplorerDriver();  

    }    
}


google浏览器也会发同样的错误,也是同样的解决方法:
eg:代码
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Project1Class {
    public static void main(String[] args) {
 
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");  
        WebDriver driver = new ChromeDriver();  

    }    
}

好像如果需要进行绘画的话,需要下载相应版本的插件。

同样的范式也解决了opera浏览器的放,
需要修改的地方是:

第一个参数:

System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");  
 增加,webdriver.chrome.driver" 中的chrome名字改为相应的浏览器名字,
 第二个参数:

修改浏览器的路径

参考链接:
http://blog.csdn.net/funi16/article/details/9036753


但是同样出现一个问题而还没有解决的:

(浏览器不能够进行运行)

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'szu', ip: '172.31.72.68', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_40'
Driver info: driver.version: OperaDriver
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
	at org.openqa.selenium.opera.OperaDriver.<init>(OperaDriver.java:169)
	at org.openqa.selenium.opera.OperaDriver.<init>(OperaDriver.java:158)
	at org.openqa.selenium.opera.OperaDriver.<init>(OperaDriver.java:115)
	at Project1Class.main(Project1Class.java:12)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'szu', ip: '172.31.72.68', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_40'
Driver info: driver.version: OperaDriver
	at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:178)
	at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:166)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:620)
	... 7 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:15176/status] to be available after 20001 ms
	at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
	at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:175)
	... 10 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
	at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
	at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
	... 11 more
Caused by: java.util.concurrent.TimeoutException
	at java.util.concurrent.FutureTask.get(FutureTask.java:205)
	at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
	... 12 more


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值