Class: SharedTools::Tools::Browser::InspectTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::Browser::InspectTool
- Includes:
- InspectUtils
- Defined in:
- lib/shared_tools/tools/browser/inspect_tool.rb
Overview
A browser automation tool for finding UI elements by their text content.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(text_content:, selector: nil, context_size: 2) ⇒ Object
-
#initialize(driver: nil, logger: nil) ⇒ InspectTool
constructor
A new instance of InspectTool.
Methods included from InspectUtils
#add_elements_from_matching_labels, #ci_contains, #clean_document, #cleaned_document, #find_elements_with_matching_text
Constructor Details
#initialize(driver: nil, logger: nil) ⇒ InspectTool
Returns a new instance of InspectTool.
26 27 28 29 |
# File 'lib/shared_tools/tools/browser/inspect_tool.rb', line 26 def initialize(driver: nil, logger: nil) @driver = driver || default_driver @logger = logger || RubyLLM.logger end |
Class Method Details
.name ⇒ Object
14 |
# File 'lib/shared_tools/tools/browser/inspect_tool.rb', line 14 def self.name = 'browser_inspect' |
Instance Method Details
#execute(text_content:, selector: nil, context_size: 2) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/shared_tools/tools/browser/inspect_tool.rb', line 31 def execute(text_content:, selector: nil, context_size: 2) raise LoadError, "InspectTool requires the 'nokogiri' gem. Install it with: gem install nokogiri" unless defined?(Nokogiri) @logger.info("#{self.class.name}##{__method__}") html = @driver.html @logger.info("#{self.class.name}##{__method__} html=#{html}") doc = cleaned_document(html: @driver.html) find_elements_by_text(doc, text_content, context_size, selector) end |