1
0
Fork 0
mirror of https://github.com/teampoltergeist/poltergeist.git synced 2022-11-09 12:05:00 -05:00

Use el.innerText for Node#text.

This ensures that e.g. `<br>` is returned as a newline. It also
simplifies the method.

Fixes #139
This commit is contained in:
Jon Leighton 2012-09-24 22:32:12 +01:00
parent 85a459a12f
commit a30175de86
3 changed files with 8 additions and 32 deletions

View file

@ -215,6 +215,9 @@ makes debugging easier). Running `rake autocompile` will watch the
* Ensure the User-Agent header can be set successfully. (Klaus Hartl)
[Issue #127]
* Use `el.innerText` for `Node#text`. This ensures that e.g. `<br>` is
returned as a newline. It also simplifies the method. [Issue #139]
### 0.7.0 ###
#### Features ####

View file

@ -141,21 +141,10 @@ class PoltergeistAgent.Node
@agent.document.evaluate('ancestor::body', @element, null, XPathResult.BOOLEAN_TYPE, null).booleanValue
text: ->
return @element.textContent if @element.tagName == 'TITLE'
return '' unless this.isVisible()
if this.insideBody()
el = @element
if @element.tagName == 'TEXTAREA'
@element.textContent
else
el = @agent.document.body
results = @agent.document.evaluate('.//text()[not(ancestor::script)]', el, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
text = ''
for i in [0...results.snapshotLength]
node = results.snapshotItem(i)
text += node.textContent if this.isVisible(node.parentNode)
text
@element.innerText
getAttribute: (name) ->
if name == 'checked' || name == 'selected'

View file

@ -204,27 +204,11 @@ PoltergeistAgent.Node = (function() {
};
Node.prototype.text = function() {
var el, i, node, results, text, _i, _ref;
if (this.element.tagName === 'TITLE') {
if (this.element.tagName === 'TEXTAREA') {
return this.element.textContent;
}
if (!this.isVisible()) {
return '';
}
if (this.insideBody()) {
el = this.element;
} else {
el = this.agent.document.body;
return this.element.innerText;
}
results = this.agent.document.evaluate('.//text()[not(ancestor::script)]', el, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
text = '';
for (i = _i = 0, _ref = results.snapshotLength; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
node = results.snapshotItem(i);
if (this.isVisible(node.parentNode)) {
text += node.textContent;
}
}
return text;
};
Node.prototype.getAttribute = function(name) {