{"record":{"id":"268303e8ef2d598c","repo":"teamcapybara/capybara","slug":"you-must-specify-both-x-and-y-for-a-click-offset","errorCode":null,"errorMessage":"You must specify both x: and y: for a click offset","messagePattern":"You must specify both x: and y: for a click offset","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/node/element.rb","lineNumber":609,"sourceCode":"        base.respond_to?(:initial_cache) ? base.initial_cache : {}\n      end\n\n      STYLE_SCRIPT = <<~JS\n        (function(){\n          var s = window.getComputedStyle(this);\n          var result = {};\n          for (var i = arguments.length; i--; ) {\n            var property_name = arguments[i];\n            result[property_name] = s.getPropertyValue(property_name);\n          }\n          return result;\n        }).apply(this, arguments)\n      JS\n\n    private\n\n      def perform_click_action(keys, wait: nil, **options)\n        raise ArgumentError, 'You must specify both x: and y: for a click offset' if nil ^ options[:x] ^ options[:y]\n\n        options[:offset] ||= :center if session_options.w3c_click_offset\n        synchronize(wait) { yield keys, options }\n        self\n      end\n    end\n  end\nend\n","sourceCodeStart":591,"sourceCodeEnd":618,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/node/element.rb#L591-L618","documentation":"Capybara raises this ArgumentError from Element#perform_click_action when a click-type action is given an offset with only one axis. The guard `nil ^ options[:x] ^ options[:y]` is true exactly when one of x:/y: was passed and the other was omitted (or explicitly nil). Offsets are a 2D coordinate, so a partial offset is always a caller bug and is rejected before any driver call.","triggerScenarios":"Calling element.click(x: 10) without y:, or click(y: 5) without x:, or explicitly passing click(x: nil, y: 20). The same perform_click_action path serves click, double_click, right_click, click_at-style helpers and double_tap/two_finger_tap on touch drivers, so any of those with a half-specified offset raises immediately.","commonSituations":"Developer copies an example that scrolls-and-clicks by horizontal offset only; dynamic offset code computes x from one variable and y from another and one evaluates to nil; wrapping click in a helper that forwards **options where the caller only set one key.","solutions":["Pass both coordinates: click(x: 10, y: 20), or pass neither for a centered click","If one axis should default (e.g. y centered), supply a concrete default yourself: click(x: offset_x, y: 0)","Check interpolated offset variables for nil before calling click when offsets come from computation"],"exampleFix":"# before\nel.click(x: 50)\n\n# after\nel.click(x: 50, y: 10)\n# or centered click with no offset at all\nel.click","handlingStrategy":"validation","validationCode":"def safe_click(el, x: nil, y: nil, **opts)\n  raise ArgumentError, 'click offset needs both x and y' if x.nil? != y.nil?\n  x.nil? ? el.click(**opts) : el.click(x: x, y: y, **opts)\nend","typeGuard":"def valid_click_offset?(opts)\n  opts.key?(:x) == opts.key?(:y)\nend","tryCatchPattern":"begin\n  el.click(x: 10, y: 20)\nrescue ArgumentError => e\n  raise unless e.message.include?('x: and y:')\n  el.click # fall back to centered click only if that is acceptable\nend","preventionTips":["Always pass click offsets as a coordinate pair (x:, y:) or omit both","When offsets are computed, nil-check each axis before calling click","In shared click helpers, reject half-offsets early with a clear message"],"tags":["capybara","argumenterror","click","offset","coordinates"],"backgroundTag":"missing-required-argument","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}