Skip to content

Commit 12e4b75

Browse files
committed
Merged origin/main into luisDVA-rep-base_pipes
2 parents ff39a31 + fb41d1d commit 12e4b75

6 files changed

Lines changed: 31 additions & 8 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Imports:
2222
rlang (>= 1.1.0),
2323
selectr,
2424
tibble,
25-
xml2 (>= 1.3)
25+
xml2 (>= 1.4.0)
2626
Suggests:
2727
chromote,
2828
covr,

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# rvest (development version)
22

3+
* Fixes `LiveHTML` objects returning 'could not find node with given id' errors if a page navigation occurred after a `$click()` event (#405).
4+
35
* New example vignette displays the same starwars data but rendered dynamically using JS, so you need to use `read_html_live()` to get the data.
46

57
# rvest 1.0.4

R/live.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ LiveHTML <- R6::R6Class(
9191
p <- self$session$Page$loadEventFired(wait_ = FALSE)
9292
self$session$Page$navigate(url, wait_ = FALSE)
9393
self$session$wait_for(p)
94-
95-
private$root_id <- self$session$DOM$getDocument(0)$root$nodeId
9694
},
9795

9896
#' @description Called when `print()`ed
@@ -202,7 +200,7 @@ LiveHTML <- R6::R6Class(
202200

203201
# https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo
204202
private$call_node_method(
205-
private$root_id,
203+
private$root_id(),
206204
paste0(".documentElement.scrollTo(", left, ", ", top, ")")
207205
)
208206
invisible(self)
@@ -262,8 +260,9 @@ LiveHTML <- R6::R6Class(
262260
),
263261

264262
private = list(
265-
root_id = NULL,
266-
263+
root_id = function() {
264+
self$session$DOM$getDocument()$root$nodeId
265+
},
267266
finalize = function() {
268267
self$session$close()
269268
},
@@ -272,7 +271,6 @@ LiveHTML <- R6::R6Class(
272271
if (new_chromote && !self$session$is_active()) {
273272
suppressMessages({
274273
self$session <- self$session$respawn()
275-
private$root_id <- self$session$DOM$getDocument(0)$root$nodeId
276274
})
277275
}
278276
},
@@ -293,7 +291,7 @@ LiveHTML <- R6::R6Class(
293291
find_nodes = function(css, xpath) {
294292
check_exclusive(css, xpath)
295293
if (!missing(css)) {
296-
unlist(self$session$DOM$querySelectorAll(private$root_id, css)$nodeIds)
294+
unlist(self$session$DOM$querySelectorAll(private$root_id(), css)$nodeIds)
297295
} else {
298296
search <- glue::glue("
299297
(function() {{

tests/testthat/html/navigate1.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Navigate 1</title>
5+
</head>
6+
<body>
7+
<a href="navigate2.html">Navigate to Page 2</a>
8+
</body>

tests/testthat/html/navigate2.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Navigate 2</title>
5+
</head>
6+
<body>
7+
<p>Success!</p>
8+
</body>

tests/testthat/test-live.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ test_that("can press special keys",{
8888
expect_equal(html_text(html_element(sess, "#keyInfo")), "]/BracketRight")
8989
})
9090

91+
test_that("can find elements after click that navigates", {
92+
skip_if_no_chromote()
93+
94+
sess <- read_html_live(html_test_path("navigate1"))
95+
sess$click("a")
96+
expect_equal(html_text2(html_element(sess, "p")), "Success!")
97+
})
9198

9299
# as_key_desc -------------------------------------------------------------
93100

0 commit comments

Comments
 (0)