This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29247 - [WebDriver Spec]: Add support for interacting with text nodes
Summary: [WebDriver Spec]: Add support for interacting with text nodes
Status: REOPENED
Alias: None
Product: Browser Test/Tools WG
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Browser Testing and Tools WG
QA Contact: Browser Testing and Tools WG
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 20860
  Show dependency treegraph
 
Reported: 2015-10-27 17:05 UTC by Mark Fulton
Modified: 2016-09-19 16:36 UTC (History)
4 users (show)

See Also:


Attachments

Description Mark Fulton 2015-10-27 17:05:46 UTC
In addition to `WebElement` can a `WebText` be added? A `WebText` would be to [text](https://developer.mozilla.org/en-US/docs/Web/API/Text) nodes what `WebElement` is to [element](https://developer.mozilla.org/en-US/docs/Web/API/Element) nodes.

Sometimes it is enough to use the element containing text but this can be problematic when an element containing text also contains elements. e.g. Without using `JavascriptExecutor` it is not possible, at least to my knowledge, to click the text `"First name: "` in `<label>First name: <input type="text" name="fname"></label>` (which, in this example, should cause the input element to get focus).

A `WebText` interface might be as follows:
```java
public interface WebText extends TakesScreenshot {
  void click();
  void sendKeys(CharSequence... keysToSend);
  void clear();
  boolean isSelected();
  String getText();
  boolean isDisplayed();
  Point getLocation();
  Dimension getSize();
  String getCssValue(String propertyName);
}
```

Other potential `WebText` methods might include `select()` (to highlight/select the text) and `select(String)` (to highlight/select a substring of the text).

Additional methods to `SearchContext` such as `findTexts(By)` and `findText(By)` would also make sense.

I believe that `WebElement`'s `submit()`, `getTagName()`, `getAttribute(String)`, `isEnabled()`, `findElements(By)`, and `findElement(By)` methods would not make sense to include. A new `WebNode` interface might even be worthwhile for both `WebElement` and `WebText` to extend to declare the common methods between them.

Notes:
1. The `sendKeys(CharSequence...)` and `clear()` methods on a `WebText` would be especially useful when dealing with text nodes in [Content Editable](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_Editable) elements. e.g. Double-click or otherwise select the text to highlight it and then send keys to overwrite it, etc.
2. `WebText.isSelected()` would return true if the user has highlighted/selected the text; otherwise false.
3. In addition to being able to "find" elements and text on the page and interact with them, the capability to send a text node over the JSON wire protocol in addition to element nodes would allow automation scripts using `JavascriptExecutor` to "list" or "query" for relevant text and element nodes on the page. e.g. Such a script might list all displayed nodes. On a simple login page it would return a list such as `[WebText[Email: ], WebElement[<input type="email">], WebText[Password: ], WebElement[<input type="password">], WebElement[<input type="submit" value="Login">]]`. This would allow the automation script to list text nodes, input elements, select elements, button elements, etc. and then interact with them inferring what they are based on their tagName, attributes, and relative positioning in the list (e.g. the password input should be the element immediately following the text "Password: "). This would seem to get closer to automating how a user interacts with a page instead of searching within a page's DOM for elements by id, name, xpath, css selector, etc.
Comment 1 Andreas Tolfsen 2015-10-31 02:58:49 UTC
I think this is a fairly interesting idea, but it is one I’m torn about.  The WebDriver API currently operates on the DOMElement level which can be surmised from the “Find Element” API name, not on the Node level.

Operating on the node level has obvious compatibility concerns, and as far as I can tell doesn’t offer any functionality that returning childNodes of a web element already does, with the added caveat that we haven’t specified a serialisation of Node.
Comment 2 Simon Stewart 2016-01-11 11:11:19 UTC
One option might be to serialize a Text node found via executing javascript to be treated as if it were an Element node (that is, assign it an ID and refer to it using that). Should a user attempt to interact with it in a way that doesn't make sense (sending keyboard input, for example) then an error could be returned.
Comment 3 John Jansen 2016-09-19 16:36:37 UTC
closed by accident.