I tried the following but still I am unable to scroll. Eg. Scroll to the 8th tile in the page.
Webpage: https://silveraisle.com/#/products?brand=Dankotuwa
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elementToScrollTo);
您可以在元素上单击使用 JavaScript 作为解决方法。
((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElements(By.cssSelector("app-product button")).get(10));
You can scroll till the web element
(new WebDriverWait(driver, 20)).until(ExpectedConditions.visibilityOfElementLocated(locator));
WebElement element = driver.findElement(locator);
Point point = element.getLocation(); JavascriptExecutor jsExecutor = ((JavascriptExecutor) driver);
int y = point.getY() - 200;
jsExecutor.executeScript("window.scrollTo(" + point.getX() + "," + y + ");", "");
Hope this will help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.