zoukankan      html  css  js  c++  java
  • ElementNotVisible exception in Selenium WebDriver

        在用webdriver做自动化测试的过程中,如果对页面上的隐藏元素,如下拉列表或是浮层进行操作的时候,常常会遇到:"org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with"提示。但是我们用isPresentByXpath()等测试当前元素的时候,返回值为True。 在网上搜索了一下解决办法,请参考:http://nitinpurswani.blogspot.com/2010/09/elementnotvisible-exception-in-selenium.html

       结合我自己的调式,用直接执行JS对应的操作比较方便。

       (1)对浮层进行输入文字
         JavascriptExecutor j= (JavascriptExecutor)driver;
         j.executeScript("document.findElementById('123').style.display='block'; ");
         然后再WebElement.sendKeys ("The words you want to type");

        (2)执行浮层上的操作,如单击
         JavascriptExecutor j= (JavascriptExecutor)driver;
         j.executeScript("document.findElementById('123').click() ");

        当然Document的很多方法都可以用来定位:
        (1)getElementById 获取对 ID 标签属性为指定值的第一个对象的引用。
        (2)getElementsByName 根据 NAME 标签属性的值获取对象的集合。
        (3)getElementsByTagName 获取基于指定元素名称的对象集合。
        
        如果要定位的页面元素没有这些儿属性,定位或操作的时候就会相对麻烦一点儿,这也是权宜之计,以后有什么好的方法,再跟大家分享。
  • 相关阅读:
    PHP线程安全
    Oracle中MD5+Base64加密实现
    1002. A+B for Polynomials (25)
    1001. A+B Format (20)
    Rails,uva 514
    Database,Uva1592
    Hello World for U
    D3.js 力导向图
    从零开始CSS(一 2016/9/21)
    从零开始HTML(三 2016/9/20)
  • 原文地址:https://www.cnblogs.com/eagleking0318/p/6521103.html
Copyright © 2011-2022 走看看