zoukankan      html  css  js  c++  java
  • Selenium: 处理弹出窗口的workaround

    在Selenium中,比较麻烦的是处理弹出窗口,虽然有selectWindow(String windowID)的方法可用,但是对于某些窗口很难拿到windowID的话,比如开发人员没在HTML中提供ID,或者getAllWindowIds()得不到弹出窗口的ID的时候,这个方法基本等于没用。

    在这个时候我们可以使用一个workaround:

    openWindow(String url, String windowID) :Opens a popup window (if a window with that ID isn't already open). After opening the window, you'll need to select it using the selectWindow command.

    比如对于一段HTML代码:<a target="newwindow" href="relative_URL">click here</a>

    可以使用xpath得到href的属性:a[text()='click here']@href 

    String url = selenium.getAttribute("a[text()='click here']@href "); 

    然后再加上server的地址,就得到弹出子窗口的地址 

    然后使用OpenWindow(URL, ID)之后

    waitForPopUp(ID, delaytime);

    selectWindow(ID);

    就选中了子窗口,然后可以在上面进行操作,比如验证文字存在,输入数据之类的

    作者:Shane
    出处:http://bluescorpio.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    npm执行清理缓存失败npm cache clean
    Vue中计算属性(computed)和监听属性函数watch的比较
    vue生命周期函数
    vue自定义指令
    vue 自定义过滤器
    vue 自定义全局按键修饰符
    线性回归模型
    python常用模块
    KNN算法的实现
    python集合(set)的运算
  • 原文地址:https://www.cnblogs.com/bluescorpio/p/1836764.html
Copyright © 2011-2022 走看看