'How to call a onclick event using Ferrum::Browser
I have a code using Selenium::WebDriver for scraping a web page.
driver = Selenium::WebDriver.for(:chrome)
driver.navigate.to(search_url)
driver.find_element(:name, 'searchText').send_keys('text')
driver.find_element(:name, 'searchButton').click
I tried to replace the code with Ferrum::Brower, but it didn't work.
browser = Ferrum::Browser.new
browser.goto(search_url)
browser.at_css('input[name=searchText]').focus.type('text')
browser.at_css('input[name=searchButton]').click
When the searchButton is clicked, the page doesn't move to a result page.
This is the input tag for search.
<input class="activeButton" onclick="submitPage(document.forms['form1'],document.forms['form1'].ListShow);" value="Search" type="button" name="searchButton">
How can I call onclick event using Ferrum?
Solution 1:[1]
Similar to type method I need to focus the Ferrum::Node instance before clicking it.
- browser.at_css('input[name=searchButton]').click
+ browser.at_css('input[name=searchButton]').focus.click
Solution 2:[2]
You can also use #submit method directly on the form.
browser.at_css('form').submit
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ironsand |
| Solution 2 | Pidav |
