• selenium中处理不带ID的弹出窗口


    在selenium中虽然有selectWindow(String windowID) 方法,但是对于一些窗口很难取得其window ID的话,如果开发人员没有在html代码中提供ID ,或者getAllWindowIds()得不到弹出窗口的ID的时候,那么这个方法基本等于没用。

    那么我们可以这样处理:
    先使用 openWindow(String url,String WindowID)来打开一个弹出窗口,然后我们在选择他。
    如对于一段html代码:
    <a target="newwindow" href="http://blog.163.com/yang_jianli/blog/url_address">注册</a>

    可以使用xpath得到href属性:
    a[text()='click here']@href
    获得弹出窗口的url:
    String url= selenium.getAttribute(”a[text()='注册']@href“);

    然后再加上server的地址,就得到弹出子窗口的地址,然后使用OpenWindow(url,idname)来打开ID为idname的弹出窗口;
    等待弹出:
    waitForPopup(id,delaytime)
    选择弹出的窗口:
    selectWindow(id)

    以上为java函数的代码,下面是python格式代码:


     url = sel.get_attribute("//a[text()=u'注册']@href")
     url2=url_base + url         #url_base为server地址
     sel.open_window(url2, 'testid')
     wait_for_pop_up(‘testid’,5)
     sel.select_window("testid")
     
    转载自:http://blog.163.com/yang_jianli/blog/static/161990006201242932840371/
  • 相关阅读:
    HDU 2883 kebab
    CSUOJ 1635 Restaurant Ratings
    CSUOJ 1638 Continued Fraction
    POJ 1852 Ants
    ZOJ 3471 Most Powerful
    CSUOJ 1637 Yet Satisfiability Again!
    如何生成CA证书
    Keepalived实现双机热备
    Nginx负载均衡的优缺点
    负载均衡之 nginx
  • 原文地址:https://www.cnblogs.com/slqt/p/4520235.html
Copyright © 2020-2023  润新知