নির্দিষ্ট DIV-এ স্ক্রল করতে জাভাস্ক্রিপ্ট এক্সিকিউটরের scrollIntoView(true) মেথড ব্যবহার করুন।
সিনট্যাক্স
WebElement div = driver.findElement(By.xpath("//div[@class='slick-track']"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", div);
জাভা কোড উদাহরণ
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
public class ScrollToDivExample {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.tutorialspoint.com/index.htm");
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
WebElement div = driver.findElement(By.xpath("//div[@class='slick-track']"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", div);
Thread.sleep(800);
driver.quit();
}
}