0

Screenshot of div element which has hidden textarea

How can I send text or provide input to the textarea box using Selenium Automation?

It is a div element with style="overflow:hidden". I have tried using XPath, but it did not work for me.

How can I provide input to the textarea shown in the image?

7
  • Can you please add the HTML tag Details? Commented May 30, 2018 at 15:49
  • Can you provide it manually ? Commented May 30, 2018 at 15:53
  • Yes I can provide text manually Commented May 30, 2018 at 17:52
  • What is the xpath you're using? Commented May 30, 2018 at 18:50
  • Right click on element>inspect>copy XPath. element = findElement(By.xpath("//*[@id="notebook-container"]/div/div[1]/div[2]/div[2]/div/div[6]/div[1]/div/div/div/div[5]/pre")); Commented May 30, 2018 at 19:14

3 Answers 3

1

Try this:

driver.findElement(By.xpath("//div[@class='input_area']//textarea"))
      .sendKeys("Your Value");
Sign up to request clarification or add additional context in comments.

5 Comments

It did not work. To be more precise it is the textarea of Jupyter notebook so you can run it in your machine
What you mean by did not work ? Please let us know error which you are getting while execute it,
Error is : text is not sent to textarea of jupyter notebook. It is showing null value
Yes, NullPointerException of which element ? It might be possible, it throws some another issue.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='input_area']//textarea"}
0

I believe you are mistaken on a few things:

  1. You don't send text to the div, you send it to the textarea.
  2. The textarea does not have a style of hidden*. It is quite visible in the screenshot you provided.
  3. The parent div does not have a style of hidden either*. If it did, you couldn't see the child textarea.
  4. The parent div does have style="overflow: hidden" which only hides the content that cannot be seen within it's 'box', but it does not hide the whole element.

I hope this helps. I recommend brushing up on HTML and CSS before going farther in trying to automate the page.

*There could be an external CSS file that could apply the style of hidden, but since we can see the textarea in the screenshot, I don't believe this is the case.

1 Comment

I know that we don't sent text to div, its textarea to where text is sent. But the problem is I am not able to send it, might be because element is not captured using xpath.
0

It is possible that the textarea the parent elements above it located inside a frame. Please do check the HTML code of your page and look for any frames wrapping the textarea.

If so, you can temporarily switch to the frame before doing sendKeys():

driver.switchTo().frame(arg). You can choose from any of the signatures below.

/**
 * Select a frame by its (zero-based) index. Selecting a frame by index is equivalent to the
 * JS expression window.frames[index] where "window" is the DOM window represented by the
 * current context. Once the frame has been selected, all subsequent calls on the WebDriver
 * interface are made to that frame.
 *
 * @param index (zero-based) index
 * @return This driver focused on the given frame
 * @throws NoSuchFrameException If the frame cannot be found
 */
WebDriver frame(int index);

/**
 * Select a frame by its name or ID. Frames located by matching name attributes are always given
 * precedence over those matched by ID.
 *
 * @param nameOrId the name of the frame window, the id of the <frame> or <iframe>
 *        element, or the (zero-based) index
 * @return This driver focused on the given frame
 * @throws NoSuchFrameException If the frame cannot be found
 */
WebDriver frame(String nameOrId);

/**
 * Select a frame using its previously located {@link WebElement}.
 *
 * @param frameElement The frame element to switch to.
 * @return This driver focused on the given frame.
 * @throws NoSuchFrameException If the given element is neither an IFRAME nor a FRAME element.
 * @throws StaleElementReferenceException If the WebElement has gone stale.
 * @see WebDriver#findElement(By)
 */
WebDriver frame(WebElement frameElement);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.