51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2969|回复: 4
打印 上一主题 下一主题

IE 无法定位元素,但ff可以,请高人指点,付代码

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2015-6-9 17:58:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 donkey0702 于 2015-6-9 18:02 编辑

代码如下:
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.FindBy;


public class ClickButton {
    WebDriver driver;

    @Before
    public void setUp() throws InterruptedException {
        System.setProperty("webdriver.ie.driver", "G:\\Selenium\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();
        driver.get("http://www.baidu.com");
       Thread.sleep(2000);

    }

    @Test
    public void login(){
        WebElement username;
        username=driver.findElement(By.xpath("//Input[@id='kw']"));

        Assert.assertEquals(username.getSize(),1);
        username.sendKeys("abc");

    }

    @After
    public void tearDown(){
        driver.quit();
    }



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

        ClickButton a=new ClickButton();
      //  a.tearDown();
        a.setUp();
        a.login();
       // a.tearDown();
    }


}

会报错, 但ff就可以定位到,请高手指点怎么修正?谢谢!

Listening on port 38152
Jun 09, 2015 5:53:12 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
Jun 09, 2015 5:53:12 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    无聊
    2020-12-8 11:20
  • 签到天数: 605 天

    连续签到: 1 天

    [LV.9]测试副司令

    2#
    发表于 2015-6-10 16:23:32 | 只看该作者
    为什么还要加个main函数。。。。直接用junit运行呀
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2020-12-8 11:20
  • 签到天数: 605 天

    连续签到: 1 天

    [LV.9]测试副司令

    3#
    发表于 2015-6-12 09:57:32 | 只看该作者
    IE不支持xpath找对象不支持吧。。。
    IE还没有实现DOM Level 3 XPath中定义的接口,但是它对xpath也有一定的支持,IE中的xpath功能主要对xml文档可用,对document的对象不可用。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
     楼主| 发表于 2015-7-3 16:36:19 | 只看该作者
    其实是对的,我忘记保存代码了,谢谢大家的指点啊
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2015-3-16 21:26
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    5#
    发表于 2015-7-22 23:10:45 | 只看该作者
    joykao 发表于 2015-6-12 09:57
    IE不支持xpath找对象不支持吧。。。
    IE还没有实现DOM Level 3 XPath中定义的接口,但是它对xpath也有一定 ...

    IE 也是支持xpath的,只不过不是原生支持,是要加载wgxpath这个库去支持的。所以支持度没有其他浏览器那么好.
      // Let the wgxpath library be compiled away unless we are on IE or Android.
      // TODO: Restrict this to just IE when we drop support for Froyo.
      if (goog.userAgent.IE || goog.userAgent.product.ANDROID) {
        wgxpath.install(goog.dom.getWindow(doc));
      }
    或者可以参考这里: https://github.com/SeleniumHQ/selenium/wiki/Xpath-In-WebDriver
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-22 09:58 , Processed in 0.073646 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表