'Is there any other way(not sendKeys) to enter text into textbox using selenium webdriver?
Is there any other way(not sendKeys) to enter text into textbox using selenium webdriver ?
Solution 1:[1]
Any other way is only to use native Javascript action to enter the value in the text box:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById("textbox_id").value='new value';);
Solution 2:[2]
@Vasntha, try mine code its tested one
driver.get("http://www.qajudge.com/");
WebElement cssValue= driver.findElement(By.xpath(".//*[@id='s']"));
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('s').value='Virender Testing
sending'");
Solution 3:[3]
WebElement name=driver.findElement(By.name("username"));
((JavascriptExecutor)driver).executeAsyncScript("arguments[0].value='admin'",name);
Solution 4:[4]
Try below one, which I tried in Gmail and it works
System.setProperty("webdriver.chrome.driver", "you .exe path here");
WebDriver driver = new ChromeDriver();
driver.get("https://accounts.google.com/");
driver.manage().window().maximize();
Thread.sleep(1000);
//Next button element
WebElement nextBtn = driver.findElement(By.id("identifierNext"));
JavascriptExecutor js = (JavascriptExecutor)driver;
//code to enter value in the email textbox
js.executeScript("document.getElementById('identifierId').value='testemail'");
//code to click on next button
js.executeScript("arguments[0].click();", nextBtn);
Solution 5:[5]
Yes, use javascript executer. Here, I have written a code that uses XPath to capture the element.
WebElement webelement = driver.findElement(By.xpath("your xpath");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].value='Techndeck';",webelement );
Solution 6:[6]
Enter text using javascriptexecutor How to use Javascriptexecutor for entering text in an element which , I want to enter text in an Textbox which does not take the input through SendKeys?. I proceeded with using Javascriptexecutor to enter the text Example 2. Get/Retrieve text with JavascriptExecutor. In this example, we are accessing a website and trying to retrieve the text written on the login button using JavascriptExecutor
How To Send Texts And Get Texts Using JavascriptExecutor?, So in such case, we use JavascriptExecutor of Selenium WebDriver library to handle Well, let's start with handling sending text data to the text area using If you still have any confusions please write in the comment below. This is another technique to send texts using JavascriptExecutor in Selenium WebDriver. Here is the sample code: ADA.
WebElement webl = driver.findElement(By.xpath(“xpath_expression”));JavascriptExecutor js = (JavascriptExecutor)driver;js.executeScript(“arguments[0].value=’SynTest’;”, webl);
1.How to enter text using JavaScript in Selenium WebDriver, Following are the commands you can use to enter text using javascript. You don't need to use sendkeys always. Syntax: JavascriptExecutor jexe To enter text within a textbox identified through an xpath you can use the following notation:
(JavascriptExecutor) driver.executeScript("document.evaluate(xpathExpresion, document, null, 9, null).singleNodeValue.innerHTML="+ DesiredText);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anirudh |
| Solution 2 | Virender Singh |
| Solution 3 | Bugs |
| Solution 4 | ragesh-ragav 1993 |
| Solution 5 | namal wijekoon |
| Solution 6 | shrawan |
