Skip to content

Commit 277f04e

Browse files
authored
fix: Setting content directly does not allow for use of DOM queries (#310)
fixes #197
1 parent 81ab27a commit 277f04e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/ferrum/frame.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def content=(html)
113113
document.close();
114114
arguments[1](true);
115115
), @page.timeout, html)
116+
@page.document_node_id
116117
end
117118
alias set_content content=
118119

lib/ferrum/page.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ def use_authorized_proxy?
325325
use_proxy? && @proxy_user && @proxy_password
326326
end
327327

328+
def document_node_id
329+
command("DOM.getDocument", depth: 0).dig("root", "nodeId")
330+
end
331+
328332
private
329333

330334
def subscribe
@@ -441,10 +445,6 @@ def combine_url!(url_or_path)
441445
(nil_or_relative ? @browser.base_url.join(url.to_s) : url).to_s
442446
end
443447

444-
def document_node_id
445-
command("DOM.getDocument", depth: 0).dig("root", "nodeId")
446-
end
447-
448448
def ws_url
449449
"ws://#{@browser.process.host}:#{@browser.process.port}/devtools/page/#{@target_id}"
450450
end

spec/frame_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@
181181
end
182182

183183
it "can set page content" do
184-
browser.content = "<html><head></head><body>Voila!</body></html>"
184+
browser.content = "<html><head></head><body>Voila! <a href='#'>Link</a></body></html>"
185185

186186
expect(browser.body).to include("Voila!")
187+
expect(browser.at_css("a").text).to eq("Link")
187188
end
188189

189190
it "gets page doctype" do

0 commit comments

Comments
 (0)