15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/headless_browser_tool/tools/click_button_tool.rb', line 15
def execute(button_text_or_selector:)
url_before = browser.current_url
browser.title
button = begin
browser.find_button(button_text_or_selector)
rescue Capybara::ElementNotFound
browser.find(button_text_or_selector)
end
button_info = {
text: button.text.strip,
value: button[:value],
type: button[:type],
disabled: button.disabled?
}.compact
browser.click_button(button_text_or_selector)
{
button: button_text_or_selector,
element: button_info,
navigation: {
navigated: browser.current_url != url_before,
from: url_before,
to: browser.current_url,
title: browser.title
},
status: "clicked"
}
end
|