0

I am trying enter characters into text field, however its not working. Below I mentioned 2 pieces of code. JS is not working at all. Where as in the first piece of code click is working but not other steps. Xpath is correct as click is working on that.

    util.driver.findElement(By.xpath("//input[@id='input-1']")).click();
    util.driver.findElement(By.xpath("//input[@id='input-1']")).clear();
    util.driver.findElement(By.xpath("//input[@id='input-1']")).sendKeys("hjgfjg");
JavascriptExecutor js = (JavascriptExecutor) util.driver;

js.executeScript("document.getElementByXpath('//input[@id='input-1']').value = 'TEST')");

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
kps
  • 71
  • 1
  • 12
  • 1
    post the markup and any scripts that run on that form. Sometimes it can be an overly complicated script that isn't keeping up with the typing. (Slowing down the typing can help if that's the case...) – pcalkins Oct 02 '19 at 21:41
  • Provided element html. BTW I tried to wait 5 seconds before and after entering one char and still I do not see its entering. – kps Oct 02 '19 at 21:46
  • try without the click or the clear... neither should be needed. – pcalkins Oct 02 '19 at 21:56
  • Same issue with out that as well. – kps Oct 02 '19 at 22:05
  • 2
    post the full markup... could be an iframe or the lack of a WebDriverWait or something like that. Are you seeing any exceptions? – pcalkins Oct 02 '19 at 22:39
  • Can you type some text in textfield manually and post html code ? – Yun Oct 03 '19 at 02:31
  • Are you getting an error, and if so what is it? – Greg Burghardt Oct 09 '19 at 22:49

3 Answers3

1

The desired element is a dynamic element so to invoke sendKeys() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.slds-input[id^='input-'][aria-describedby^='help-message-']"))).sendKeys("hjgfjg");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='slds-input' and starts-with(@id, 'input-')][starts-with(@aria-describedby, 'help-message-')]"))).sendKeys("hjgfjg");
    
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try use Actions:

WebElement input = util.driver.findElement(By.xpath("//input[@id='input-1']"));
Actions action = new Actions(util.driver);
action.moveToElement(input).click().sendKeys("test").build().perform();

Following import:

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
frianH
  • 7,295
  • 6
  • 20
  • 45
0

Probably you can try below workarounds:

  1. Try clicking on the textbox first and then call sendKeys().
  2. Angular can't process input events when they arrive too fast. As a workaround, you would need to send single characters with a small delay between each.

Selenium sendKeys are not sending all characters

  1. You can try using Actions class.