51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1828|回复: 2
打印 上一主题 下一主题

frame下无法定位到“添加”按钮

[复制链接]
  • TA的每日心情
    开心
    2015-8-5 13:21
  • 签到天数: 7 天

    连续签到: 2 天

    [LV.3]测试连长

    跳转到指定楼层
    1#
    发表于 2014-12-8 15:51:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    定位iframe下的“添加”按钮:

    (见图)

    代码如下:

    String URL = driver.findElement(By.name("workspace")).getAttribute("src").toString();
        driver.get(URL);
      
        driver.findElement(By.xpath("/html/body/div[1]/div[3]/div/a[1]"));
       
        //WebElement btn1 = driver.findElement(By.cssSelector("iconButton opera_971"));
        // btn1.click();
        // driver.findElement(By.xpath( "//a[@onclick = 'add()']" )).click();



    错误如下:
    org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div[3]/div/a[1]"}
    Command duration or timeout: 10 milliseconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:58'
    System info: host: '0308-PC', ip: '172.230.140.39', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0'
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=34.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
    Session ID: 95a29865-3ca8-4b39-98f1-a1f02fd99f9f
    为什么定位不到frame中的元素?


    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2020-2-2 19:27
  • 签到天数: 169 天

    连续签到: 1 天

    [LV.7]测试师长

    2#
    发表于 2014-12-9 16:02:45 | 只看该作者
    确认一个你要测试的页面是否为嵌套的三级和四级页面吧,如果是的话对象不好识别的,这也是我遇到的问题,一直也没有很好的解决方案

    评分

    参与人数 1测试积点 +10 收起 理由
    lsekfe + 10 希望能给LZ一定的见解

    查看全部评分

    回复 支持 反对

    使用道具 举报

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

    连续签到: 1 天

    [LV.9]测试副司令

    3#
    发表于 2014-12-9 18:21:18 | 只看该作者
    iframe之间是要切换的
            /**
             * Switch frames
             * @param frame
             */

            public static void switchToFrame(String frame) {
                    driver.switchTo().defaultContent().switchTo().frame(frame);
            }
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-5-5 12:31 , Processed in 0.067396 second(s), 24 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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