কম্পিউটার টিউটোরিয়াল

Selenium-এ Java ব্যবহার করে ওয়েবপেজ স্ক্রল ডাউন করা


আমরা Selenium-এ Java ব্যবহার করে একটি ওয়েবপেজ স্ক্রল ডাউন করতে পারি। Selenium সরাসরি স্ক্রল হ্যান্ডেল করতে পারে না। এটি Javascript Executor-এর সাহায্য নেয় একটি এলিমেন্ট পর্যন্ত স্ক্রলিং অ্যাকশন সম্পাদন করতে।

প্রথমে, আমাদের সেই এলিমেন্টটি লোকেট করতে হবে যার পর্যন্ত স্ক্রল করতে হবে। তারপর, Javascript Executor ব্যবহার করে জাভাস্ক্রিপ্ট কমান্ড রান করতে হবে। Selenium-এ জাভাস্ক্রিপ্ট কমান্ড রান করতে executeScript মেথড ব্যবহার করা হয়। জাভাস্ক্রিপ্ট-এ scrollIntoView মেথড ব্যবহার করে true আর্গুমেন্ট হিসেবে পাস করতে হবে।

সিনট্যাক্স:

WebElement elm = driver.findElement(By.name("name")); 
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elm);

উদাহরণ

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.JavascriptExecutor; 

public class ScrollAction{ 
    public static void main(String[] args) { 
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\geckodriver.exe"); 
        WebDriver driver = new FirefoxDriver(); 
        // implicit wait
        driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); 
        // অ্যাপ্লিকেশন লঞ্চ
        driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); 
        // এলিমেন্ট চিহ্নিত
        WebElement n = driver.findElement(By.xpath("//*[text()='Contact']")); 
        // Javascript executor
        ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", n); 
    } 
}

আউটপুট

Selenium-এ Java ব্যবহার করে ওয়েবপেজ স্ক্রল ডাউন করা

  1. Selenium WebDriver জাভায় চাইল্ড ব্রাউজার উইন্ডো ক্লোজ করা

  2. জাভা ওপেনসিভি (OpenCV) ব্যবহার করে বৃত্ত আঁকার পদ্ধতি

  3. জাভা ওপেনসিভি (OpenCV) ব্যবহার করে আয়ত আঁকার পদ্ধতি

  4. জাভা ওপেনসিভি (OpenCV) ব্যবহার করে রেখা আঁকার পদ্ধতি