简体   繁体   English

WebDriver可在Chrome上运行,但不能在Internet Explorer上运行

[英]WebDriver works on Chrome but no on Internet Explorer

Hello im using webdriver and first time works excellent, but the next day it only works on google chrome with the same code, on IE says that cant find the element and im using a very simple code that is: 您好,我使用webdriver并第一次使用效果很好,但是第二天它只能在使用相同代码的google chrome上运行,在IE上说无法找到该元素,因此我使用了非常简单的代码:

   public class Test {
public static void main(String[] args) throws InterruptedException {

    //WebDriver driver = new InternetExplorerDriver();
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.google.com");
    Thread.sleep(3000);
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("ELTUTO");
    }

and the error says: 错误显示:

Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 14 milliseconds Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32' System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25' 线程“主”中的异常org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口上找到元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:14毫秒构建信息:版本:'2.33.0' ,修订:“ 4e90c97”,时间:“ 2013-05-22 15:33:32”系统信息:os.name:“ Windows 7”,os.arch:“ x86”,os.version:“ 6.1”,java .version:“ 1.7.0_25”

Only says that when im exceuting on IE on google chrome works good 只说当我在谷歌浏览器上在IE上执行时效果很好

It's because you're always creating an instance of WebDriver driver = new ChromeDriver(); 这是因为您总是在创建WebDriver driver = new ChromeDriver();的实例WebDriver driver = new ChromeDriver();

If you want to use it on IE then create an instance of WebDriver driver = new InternetExplorerDriver(); 如果要在IE上使用它,则创建一个WebDriver driver = new InternetExplorerDriver();的实例WebDriver driver = new InternetExplorerDriver();

Edit 编辑

Also, the InternetExplorerDriver needs to be correctly configured for it to work. 另外,还需要正确配置InternetExplorerDriver才能使其正常工作。 Please check the required configuration part on the selenium wiki... 请在Selenium Wiki上检查所需的配置部分...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM