আমরা নিম্নলিখিত উপায়ে সেলেনিয়াম-এ সম্পাদনা বাক্সের মান পেতে পারি -
-
getText () পদ্ধতি ব্যবহার করে।
-
ক্লাস JavascriptExecutor ব্যবহার করে।
পদ্ধতি getText ().
সহ কোড বাস্তবায়নউদাহরণ
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 GetValueScripting {
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);
String text = driver.findElement(By.className("gsc-input")).getText();
System.out.println("Extracted text is " + text);
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;
import org.openqa.selenium.JavascriptExecutor;
public class ExtractValueScripting {
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);
// create Javascript object
JavascriptExecutor js = (JavascriptExecutor)driver;
// Issue command to extract the text
String text = js.executeScript("return document.getElementById(' gsc-i-id1').value").toString();
System.out.println("Extracted text is" + text);
driver.close();
}
}