In this post, we will see Selenium Enter Text without sendKeys | How to type in a textbox without using sendKeys()?
Program Code (EnterTextWithoutSendkeys.java) :
package main;
import java.time.Duration;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class EnterTextWithoutSendkeys {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://mail.rediff.com/cgi-bin/login.cgi");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
JavascriptExecutor js=(JavascriptExecutor)driver;
//js.executeScript("document.getElementById('login1').value=\"abcde\"");
//js.executeScript("document.getElementsByName('login')[0].value=\"12345\"");
js.executeScript("document.querySelector('#login1').value=\"abcd1234\"");
}
}
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=snhs_gLaaTM
No comments:
Post a Comment