gpt4 book ai didi

java - 我们如何在 selenium java 中检查滚动条是否可滚动?

转载 作者:太空宇宙 更新时间:2023-11-04 10:08:31 26 4
gpt4 key购买 nike

我必须检查水平滚动条是否可滚动。我尝试检查元素是否显示,该元素在水平滚动之后使用Javascript scrollIntoView 但它如何确保滚动条正常工作。

因为滚动条位置没有改变 scrollIntoView 仅滚动元素并使其显示在屏幕上。但滚动条不滚动。

最佳答案

尝试使用以下选项来水平滚动:

// scroll at a particular element

WebElement e1 =

driver.findElement(By.xpath(“//input [@id=’ElementID’]”));

((JavascriptExecutor)driver).executeScript(“arguments[0].scrollIntoView();”, e1);

Where ‘e1’ is the locator where you want to scroll.

// scroll at a particular coordinate,.

((JavascriptExecutor)driver).executeScript(“window.scrollBy(200,300)”);



// scroll horizontally in the right direction.
((JavascriptExecutor)driver).executeScript(“window.scrollBy(2000,0)”);

// scroll horizontally in the left direction.
((JavascriptExecutor)driver).executeScript(“window.scrollBy(-2000,0)”);

关于java - 我们如何在 selenium java 中检查滚动条是否可滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52639724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com