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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    js 生成 yyyy-mm-dd 格式的逼格姿势
    使用chrome联调不在同一个域的请求
    linux命令收集
    spring component-scan filter
    命令别名alias设置
    vi命令的使用
    Git中的文件状态和使用问题解决
    Git常用命令
    Maven
    MySQL命令
  • 原文地址:https://www.cnblogs.com/bluescorpio/p/1836764.html
Copyright © 2011-2022 走看看