I have tried a few ways of adding scrolling to tables, but just one of them works correctly. What is the difference between them?
First:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", Element);
Second:
WebElement element1 = driver.findElement(By.id("scrolled_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element1);
Third:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)");
Fourth:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
Element
object in the first example? Based on the documentation, the inclusion oftrue
inscrollIntoView(true)
shouldn't make a difference because by defaulttrue
is used forscrollIntoView()
. – ReferentscrollTo(x,y)
does what it suggests -- i.e. scrolls to the coordinates you have provided. Meaning.scrollTo(1,1)
will cause the pixel position of1,1
to be top-left of your viewport. – ReferentWebElement Element = driver.findElement(By.linkText("blaBla"));
and i dont know why it worked but only the first one worked, strange, but real. scrollTo is not listed, so we have five? or what are the total options? – BilliardsBy.linkText()
, the second example is byBy.id()
. I won't be able to tell you why it didn't work -- it really depends on the element you're trying to find. By the way to prevent too many comments I have added more thoughts in an answer below. Do look through it and accept it if it helps you! – Referent