Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Last active May 16, 2019 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleepless-se/1b3e868ad79ebbec2960632ac6b55260 to your computer and use it in GitHub Desktop.
Save sleepless-se/1b3e868ad79ebbec2960632ac6b55260 to your computer and use it in GitHub Desktop.
inputTextByJavascriptExcuter in java for selenium
//import
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
/**
* @param xpath
* Please select text box element
* @param text
* Please set your text
* @param driver
* Please set your WebDriver
*/
public void inputTextByJSE(String xpath, String text,WebDriver driver) {
JavascriptExecutor jse = (JavascriptExecutor) driver;
WebElement elm = driver.findElement(By.xpath(xpath));
String script = "arguments[0].value='" + text + "';";
jse.executeScript(script, elm);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment