不同的滚动选项之间有什么区别? [英] What is the difference between the different scroll options?
本文介绍了不同的滚动选项之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了几种向表添加滚动的方法,但是只有其中一种可以正常工作.他们之间有什么区别?
I have tried a few ways of adding scrolling to tables, but just one of them works correctly. What is the different between them?
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", Element);
第二:
WebElement element1 = driver.findElement(By.id("scrolled_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element1);
第三:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)");
第四:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
推荐答案
Element.scrollIntoView()
Element.scrollIntoView()方法滚动在浏览器窗口的视口中被调用的元素.
Element.scrollIntoView()
Element.scrollIntoView() method scrolls the element on which it's called into the Viewport of the browser window.
-
语法:
Syntax:
-
element.scrollIntoView()
-
element.scrollIntoView(alignToTop)
//布尔参数 -
element.scrollIntoView(scrollIntoViewOptions)
//对象参数
element.scrollIntoView()
element.scrollIntoView(alignToTop)
// Boolean parameterelement.scrollIntoView(scrollIntoViewOptions)
// Object parameter
您的用例:
-
executeScript("arguments[0].scrollIntoView();", Element)
:这行代码会将元素滚动到浏览器窗口的可见区域. -
executeScript("arguments[0].scrollIntoView(true);", element1)
:这行代码将滚动元素以使其与视口" .此选项对应于scrollIntoViewOptions: {block: "start", inline: "nearest"}
.基本上,这是默认值. -
executeScript("arguments[0].scrollIntoView(false)", element1);
:此代码行将滚动元素以使其与视口" .此选项对应scrollIntoViewOptions: {block: "end", inline: "nearest"}
.
executeScript("arguments[0].scrollIntoView();", Element)
: This line of code will scroll the element into the visible area of the browser window.executeScript("arguments[0].scrollIntoView(true);", element1)
: This line of code will scroll the element to be aligned to the top of the Viewport of the scrollable ancestor. This option corresponds toscrollIntoViewOptions: {block: "start", inline: "nearest"}
. Basically, this is the default value.executeScript("arguments[0].scrollIntoView(false)", element1);
: This line of code will scroll the element to be aligned to the bottom of the Viewport of the scrollable ancestor. This option corresponds toscrollIntoViewOptions: {block: "end", inline: "nearest"}
.
window.scrollBy()方法滚动给定数量的文件在当前窗口中显示.
window.scrollBy() method scrolls the document in the current window by the given amount.
-
语法:
Syntax:
-
window.scrollBy(x-coord, y-coord)
-
window.scrollBy(options)
window.scrollBy(x-coord, y-coord)
window.scrollBy(options)
参数:
-
x-coord
是要滚动的水平像素值. -
y-coord
是要滚动的垂直像素值. -
options
是ScrollToOptions
词典
x-coord
is the horizontal pixel value that you want to scroll by.y-coord
is the vertical pixel value that you want to scroll by.options
is aScrollToOptions
dictionary.
您的用例:
-
executeScript("window.scrollBy(0,1000)")
:这行代码将在窗口中向下滚动文档,将滚动像素0
水平像素和1000
您要滚动的垂直像素.
executeScript("window.scrollBy(0,1000)")
: This line of code will scroll the document in the window down by0
horizontal pixels and1000
vertical pixels that you want to scroll by.
Window.scrollTo()方法滚动到文档中的一组特定坐标.
Window.scrollTo() method scrolls to a particular set of coordinates in the document.
-
语法:
Syntax:
-
window.scrollTo(x-coord, y-coord)
-
window.scrollTo(options)
window.scrollTo(x-coord, y-coord)
window.scrollTo(options)
参数:
-
x-coord
是要在左上方显示的文档水平轴上的像素. -
y-coord
是要显示在文档左上角的文档垂直轴上的像素. -
options
是ScrollToOptions
词典
x-coord
is the pixel along the horizontal axis of the document that you want displayed in the upper left.y-coord
is the pixel along the vertical axis of the document that you want displayed in the upper left.options
is aScrollToOptions
dictionary.
您的用例:
-
executeScript("window.scrollTo(0, document.body.scrollHeight)")
:这行代码将文档在窗口中向下滚动到页面的bottom
.
executeScript("window.scrollTo(0, document.body.scrollHeight)")
: This line of code will scroll the document in the window down to thebottom
of the page.
这篇关于不同的滚动选项之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文