【问题标题】:not able to select hidden link - selenium无法选择隐藏链接 - selenium
【发布时间】:2013-06-25 02:35:22
【问题描述】:

当我将鼠标悬停到网页中的特定框架时,​​我必须选择网页链接,按钮(指向下一页的链接)将可见。

WebElement mainElement = driver.findElement(By.xpath(<frame xpath >));

Actions builder = new Actions(driver);
builder.moveToElement(mainElement);
WebElement button1 = driver.findElement(By.xpath("//*[@id='currentSkills']/div[1]/div/a"));
builder.moveToElement(button1).click().perform();

我仍然无法选择特定链接 当我执行时,出现以下错误 org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:131 毫秒

但是当我在 AUT 期间将鼠标指针悬停在特定帧上时(只是为了移动到特定帧而不点击任何东西),那么测试正在成功执行。

我知道这可以由 JS 处理。但我想知道 selenium webdriver 中是否有任何解决方案

【问题讨论】:

    标签: java selenium webdriver testng


    【解决方案1】:

    在各种浏览器的某些驱动程序上,有时像这样的自定义操作将不起作用,除非您在创建驱动程序时明确启用本机事件:

    FirefoxProfile profile = new FirefoxProfile();   
    profile.setEnableNativeEvents(true);     
    driver = new FirefoxDriver(profile);
    

    或在为远程驱动程序创建 DesiredCapabilities 时设置它的另一种方法

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
    desiredCapabilities.setCapability("nativeEvents", true);
    

    【讨论】:

      【解决方案2】:

      在使用动作链时,我一直发现在同一个链中执行所有动作更可靠。因此,与其“暂停”寻找现在显示的元素,不如尝试在链中这样做。

      WebElement mainElement = driver.findElement(By.xpath(<frame xpath >));
      Actions builder = new Actions(driver);
      builder.moveToElement(mainElement).moveToElement(driver.findElement(By.xpath("//*[@id='currentSkills']/div[1]/div/a"))).click().perform();
      

      希望这会有所帮助。

      【讨论】:

      • 非常感谢马克...它在 chrome 中按预期工作...但在 FF 中仍然遇到一些问题...
      • 说实话,我自己在这两种浏览器之间也遇到过类似的问题——Chrome 只能使用与上述类似的东西,但 Firefox 可能会出现问题。那么您在 Firefox 中看到同样的异常还是发生了其他事情?
      • Firefox 中的相同异常... :-(
      • 只是好奇,如果您在浏览器中观看测试,您是否看到想要的元素出现了,即使只是短暂的一秒钟?
      • 您可能需要在您的 Firefox 驱动程序上启用本机事件才能使其正常工作。在你创建你的驱动程序之前,修改你交给它的配置文件FirefoxProfile profile = new FirefoxProfile();profile.setEnableNativeEvents(true);driver = new FirefoxDriver(profile);
      【解决方案3】:
      FirefoxProfile profile = new FirefoxProfile();   
               profile.setEnableNativeEvents(true);     
               driver = new FirefoxDriver(profile);    
      
      WebElement searchBtn = driver.findElement(By.xpath(""));
          WebElement searchBtn1 = driver.findElement(By.xpath(""));
          Actions action = new Actions(driver);
          action.moveToElement(searchBtn).moveToElement(searchBtn1).click().build().perform();
      

      【讨论】:

        【解决方案4】:

        我的视图是需要在对象上执行鼠标悬停以使其可见,然后单击该元素。

        WebElement mainElement = driver.findElement(By.xpath(<frame xpath >));
        
        Actions builder = new Actions(driver);
        
        builder.moveToElement(mainElement).moveToElement(driver.findElement(By.xpath("//*[@id='currentSkills']/div[1]/div/a"))).build().perform();
        
        driver.findElement(By.xpath("//*[@id='currentSkills']/div[1]/div/a")).click();
        

        请让我知道上述脚本是否有效。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-12-01
          • 1970-01-01
          • 2013-06-29
          • 2014-04-08
          相关资源
          最近更新 更多