0

I am using selenium and i need to write to and xpath element so far i managed to successfully make a click on it by using this

driver.findElement(
     By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Vehicle:'])[1]/following::ul[1]"))
     .click();

Then i need to write on it, i've been using this

WebElement ele = driver.findElement(By.xpath("(.//*[normalize space(text()) and normalize-space(.)='Vehicle:'])[1]/following::ul[1]"));

     ((JavascriptExecutor) driver).executeScript("arguments[0].value='SED'",ele);

In the example i tried to write SED but i can't it to enter any text

  • I believe you are pointing to the wrong node. How can you send value to `ul`? Is there a text field with in `ul`? Can you post the html of the `ul` with its children. – supputuri Aug 28 '19 at 15:12
  • `
    ` @supputuri
    – blazedosan002 Aug 28 '19 at 15:20
  • `ul.select2-choices input.select2-input` is the css that you can use. If you want to use the xpath then `//ul[@class='select2-choices']//input[@class='select2-input']`. – supputuri Aug 28 '19 at 21:39

1 Answers1

0

If you have identified your element correctly and you have used .click() on to get inside the textbox, you can use sendKeys() to enter the value ("SED") in it. In this case you do not need to create a JavascriptExecutor instance

Example:

driver.findElement(By.xpath("(.//*[normalize space(text()) and normalize-space(.)='Vehicle:'])[1]/following::ul[1]")).sendKeys("SED");
work_ishaan
  • 354
  • 1
  • 8
  • Thank you for your answer I already tried that but it sends me this error `error":"element not interactable","message":"Element
      is not reachable by keyboard"`
    – blazedosan002 Aug 28 '19 at 15:13
  • `ul` is not an input tag. You are definitely pointing to a wrong element. – work_ishaan Aug 28 '19 at 15:23