Skip to content

Commit 25daaa4

Browse files
author
spicychickensauce
committed
Simplify get_css_path by using nth_child
1 parent 411deb9 commit 25daaa4

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

test/lazy_html_test.exs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,11 @@ defmodule LazyHTMLTest do
307307
parent = LazyHTML.parent_node(node)
308308

309309
if Enum.count(parent) > 0 do
310-
siblings =
311-
LazyHTML.child_nodes(parent)
312-
|> Enum.reject(fn n -> LazyHTML.tag(n) == [] end)
313-
314310
[tag] = LazyHTML.tag(node)
315-
i = Enum.find_index(siblings, fn n -> LazyHTML.equals?(n, node) end)
311+
[i] = LazyHTML.nth_child(node)
316312
get_css_path(parent, [{tag, i} | acc])
317313
else
318-
acc |> Enum.map_join(" > ", fn {tag, i} -> "#{tag}:nth-child(#{i + 1})" end)
314+
acc |> Enum.map_join(" > ", fn {tag, i} -> "#{tag}:nth-child(#{i})" end)
319315
end
320316
end
321317

0 commit comments

Comments
 (0)