【问题标题】:Looking for a scroll bar with Selenium and java寻找带有 Selenium 和 java 的滚动条
【发布时间】:2015-03-19 06:10:03
【问题描述】:

这与其他滚动条问题略有不同。我需要验证滚动条不存在。在开发此功能之前,我检查了页面并发现了一个 xpath "//*[contains(@id,'scroller')]"。 现在代码已经开发完成,没有滚动条,但 xpath 仍然存在。这是html sn-p:

<div tabindex="-1" id="pt1:r1:0:pt1:t1::scroller" style="position: absolute; overflow: auto; z-index: 0; width: 456px; top: 32px; height: 119px; right: 0px;">
    <div style="width: 456px; height: 119px; visibility: hidden;"></div>
</div>

我不能只做一个

List<WebElement> a = driver.findElements(By.xpath("//*[contains(@id,'scroller')])

然后断言s.size() == 0,因为即使没有滚动条,该元素仍然存在。

我也试过了

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", searchColumn);

其中 searchColumn 是表格的最右侧列(仍在视图中),该列不应再有滚动条。我以为如果没有滚动条,这会断言,但事实并非如此。

知道如何验证没有滚动条吗?

谢谢

【问题讨论】:

    标签: java html selenium xpath


    【解决方案1】:

    Scorllbar 不是您可以使用 Webdriver 的 findElement 方法找到的 WebElement。

    您的开发人员可能已修改 CSS 属性以隐藏滚动条。

    检查这个例子。它取自 W3Schools CSS 演示。

    div.scroll {
        background-color: #00FFFF;
        width: 100px;
        height: 100px;
        overflow: scroll;
    }
    
    div.hidden {
        background-color: #00FF00;
        width: 100px;
        height: 100px;
        overflow: hidden;
    }
    <p>The overflow property specifies what to do if the content of an element exceeds the size of the element's box.</p>
    
    <p>overflow:scroll</p>
    <div class="scroll">You can use the overflow property when you want to have better control of the layout. The default value is visible.</div>
    
    <p>overflow:hidden</p>
    <div class="hidden">You can use the overflow property when you want to have better control of the layout. The default value is visible.</div>

    因此,访问表格元素并检查样式属性或与开发人员一起检查他修改的属性。

    【讨论】:

      猜你喜欢
      • 2020-04-20
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 2012-03-15
      相关资源
      最近更新 更多