MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

Update ElementServer.getText() method. #277

Closed vkepin closed 7 years ago

vkepin commented 7 years ago

Change JSObject attribute 'innerText' to 'textContent' according w3c standart https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent

hollingsworthd commented 7 years ago

According to the Selenium WebElement API docs, the getText method gets "the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements, without any leading or trailing whitespace."

By that description, I think we would have to stay with innerText. What do you think?

hollingsworthd commented 7 years ago

Note if you need the textContent calling WebElement.getAttribute("textContent") should work.

vkepin commented 7 years ago

The reason of that change is that our team faced issue with getText() from textarea element, unlike other WebDrivers, JBrowser returns empty String for this.

As about visibility of text, I guess according JBrowser implementation of ElementServer.getText() : 558: if ((Boolean) node.eval(IS_VISIBLE)) -> check for visibility 560: return text instanceof String ? ((String) text).trim() : ""; -> will remove leading or trailing whitespaces

That's why I propose this update

hollingsworthd commented 7 years ago

If you want to make the getText method contain a conditional, such as if(textarea){ return textContent; } return innerText; I'm ok with that. There are at least several special cases like that already.

The check that exists for whether the element is visible won't help when when, e.g., a hidden span is inside a div of text, and you ask for the text of the div.

vkepin commented 7 years ago

Updated

hollingsworthd commented 7 years ago

Looks good. Thanks for working on this and contributing it!

hollingsworthd commented 7 years ago

Fyi, recent changes are released in v0.17.8