Skip to content

Commit

Permalink
fill CHANGELOG/README for implemented Ferrum::Browser#wait_for_select…
Browse files Browse the repository at this point in the history
…or method
  • Loading branch information
Mifrill committed Jan 15, 2022
1 parent cf74591 commit 3b09739
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Added

- `Ferrum::Browser#wait_for_selector`: returns instance of `Ferrum::Node` that's matched by provided selector.
- Alias `Ferrum::Frame#content=` to `Ferrum::Frame#set_content`
- Alias `Ferrum::Node#propery` to `Ferrum::Node#[]`
- Implement `Ferrum::Network#blacklist=` and `Ferrum::Network#whitelist=`
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ browser.go_to("https://google.com/")
browser.body # => '<html itemscope="" itemtype="http://schema.org/WebPage" lang="ru"><head>...
```

#### wait_for_selector : `Node`

```ruby
browser.wait_for_selector(css: "body", timeout: 5000) # => [Node]
browser.wait_for_selector(xpath: "//body", interval: 200) # => [Node]
```

* options `Hash`
* `:css` (String) - selector in css format, not specified by default.
* `:xpath` (String) - selector in xpath format, not specified by default.
* `:timeout` (Integer) - timeout for the selector-waiting in milliseconds, 3000 ms by default.
* `:interval` (Integer) - interval that used to compute attempts for the selector-waiting (max attempts = timeout / interval), 100 by default.

## Screenshots

Expand Down
3 changes: 1 addition & 2 deletions lib/ferrum/frame/dom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def wait_for_selector(css: nil, xpath: nil, timeout: 3000, interval: 100)
return reject(new Error("Not found element match the selector: " + selector));
}
var element = isXpath
? document.
evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
? document.evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
: document.querySelector(selector);
if (element !== null) {
return resolve(element);
Expand Down

0 comments on commit 3b09739

Please sign in to comment.