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

3
  • 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. Commented Aug 28, 2019 at 15:12
  • <ul class="select2-choices"> <li class="select2-search-field"> <input type="text" autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false" class="select2-input" id="s2id_autogen8" tabindex="2" style="width: 10px;"> </li></ul> @supputuri Commented Aug 28, 2019 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']. Commented Aug 28, 2019 at 21:39

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer I already tried that but it sends me this error error":"element not interactable","message":"Element <ul class=\"select2-choices\"> is not reachable by keyboard"
ul is not an input tag. You are definitely pointing to a wrong element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.