zoukankan      html  css  js  c++  java
  • 【转载】webdriver 自动化测试如何定位到动态变化ID的iframe框内

    大家知道,在自动化测试脚本编写过程中,如果页面上跳出一个iframe框时,我们是定位不到框内内容的,可以通过

    driver.findElement(By.id(""));

    driver.switchTo().frame("id|name");

    driver.switchTo().defaultContent();

    来实现进入iframe和进入默认页面。今天在编写脚本过程中遇到了一个fancybox框,框内嵌入了iframe,但是该iframe的id是动态变化的,因此无法定位到iframe之内。

    解决的办法是我们可以通过获取iframe的id来进入iframe,代码如下:

    driver.switchTo().frame(e(By.xpath("//div[@class='fancybox-inner']/iframe")).getAttribute("id"));

    其中函数e的源代码如下:

    protected WebElement e(By by) {
      try {
       waitUtilElementExist(by);
       return driver.findElement(by);
      } catch (Exception e) {
       fail("can not find element by:" + by);
      }
      return null;
     }

  • 相关阅读:
    PHP安装linux
    nginx 安装
    Redis安装
    linux启动http服务
    收藏的有用的网页
    laravel框架部署后有用命令
    .net 报错access to the path c: empimagefilesmsc_cntr_0.txt is denied
    oracle 触发器
    学习Auxre记录
    mysql数据库索引
  • 原文地址:https://www.cnblogs.com/glre09/p/3231782.html
Copyright © 2011-2022 走看看