Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use textContent to retrieve text of nodes. #216

Closed
wants to merge 1 commit into from

2 participants

@tristandunn

I ran into issues checking for text within a node, similar to #195. I'm setting the width and height on html and body to 100% and hiding overflow on body. The text was within an absolute positioned container spanning the height of the page. When overflow was set to auto or hidden on the container the text would no longer be found.

I was unable to recreate the issue even with the full HTML and CSS from my application. To avoid spending all weekend trying to recreate it in a test case I verified the textContent change works by removing the line in the original fix and by using it in my application.

There are some differences between innerText and textContent, best explained by MDN:

Internet Explorer introduced element.innerText. The intention is pretty much the same with a couple of differences:

  • Note that while textContent gets the content of all elements, including script and style elements, the mostly equivalent IE-specific property, innerText, does not.
  • innerText is also aware of style and will not return the text of hidden elements, whereas textContent will.
  • As innerText is aware of CSS styling, it will trigger a reflow, whereas textContent will not.

The one difference I can see possibly being an issue is the fact that textContent will return the text of hidden elements. There's currently no test for it though, so perhaps it is not an issue.

@duelinmarkers

Returning the text of hidden elements (as well as script elements) would be a problem for me (and, I suspect, many other users).

@tristandunn tristandunn closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 25, 2011
  1. @tristandunn
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 8 deletions.
  1. +0 −1  src/WebPage.cpp
  2. +1 −7 src/capybara.js
View
1  src/WebPage.cpp
@@ -20,7 +20,6 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
this, SLOT(frameCreated(QWebFrame *)));
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
- this->setViewportSize(QSize(1680, 1050));
}
void WebPage::setCustomNetworkAccessManager() {
View
8 src/capybara.js
@@ -32,13 +32,7 @@ Capybara = {
},
text: function (index) {
- var node = this.nodes[index];
- var type = (node.type || node.tagName).toLowerCase();
- if (type == "textarea") {
- return node.innerHTML;
- } else {
- return node.innerText;
- }
+ return this.nodes[index].textContent;
},
attribute: function (index, name) {
Something went wrong with that request. Please try again.