একটি CSS এক্সপ্রেশন তৈরি করার বিভিন্ন পদ্ধতি নীচে তালিকাভুক্ত করা হয়েছে -
-
CSS নির্বাচক হিসাবে একটি ক্লাস ব্যবহার করা
এটি সেই নির্দিষ্ট শ্রেণীর সমস্ত ওয়েব উপাদান নির্বাচন করবে। (উদাহরণস্বরূপ (.) দ্বারা প্রতিনিধিত্ব করা হয়েছে - .classname)
-
সিএসএস নির্বাচক হিসাবে একটি আইডি ব্যবহার করা।
এটি সেই নির্দিষ্ট আইডির ওয়েব উপাদান নির্বাচন করবে। (উদাহরণস্বরূপ (#) দ্বারা প্রতিনিধিত্ব - #ID)
-
নির্বাচক হিসাবে একটি ট্যাগনাম এবং বৈশিষ্ট্য মান ব্যবহার করা।
এটি সেই নির্দিষ্ট বৈশিষ্ট্য মান সমন্বয়ের ওয়েব উপাদান নির্বাচন করবে। (ট্যাগনাম দ্বারা প্রতিনিধিত্ব করা হয় [attribute='value'])
উদাহরণ
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class CssExpression {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://www.tutorialspoint.com/index.htm";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//Using class with . For css expression
driver.findElement(By.cssSelector(".gsc- input")).sendKeys("Selenium");
driver.close();
}
} উদাহরণ
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class CssId {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://www.tutorialspoint.com/index.htm";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//Using id with # for css expression
driver.findElement(By.cssSelector("#gsc-i- id1")).sendKeys("Selenium");
driver.close();
}
} উদাহরণ
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class CssTagExp {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://www.tutorialspoint.com/index.htm";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//Using id tagname attribute combination for css expression
driver.findElement(By.cssSelector("input[name=’search’]")).
sendKeys("Selenium");
driver.close();
}
}