Home > database >  Problem with monitor resolution in Capybara object identification
Problem with monitor resolution in Capybara object identification

Time:06-07

Friends, when I run on a 15″ monitor, capybara is not able to click on a specific menu item, but when I run on a 29″ monitor, the test works perfectly. How to adjust this in a way that the test runs regardless of monitor size. I am using the following configuration below. Thank'U

Capybara.default_driver = driver
   Capybara.default_max_wait_time = 30
   Capybara.page.current_window.resize_to(1366, 768)
   Capybara.page.driver.browser.manage.window.maximize

CodePudding user response:

You can resize the window to width: 2000, height: 2000 and see if works.

Or Your element might not be visible to click. So, you can add to scroll to that element and click it

For that, add a separate method like below

def scroll_to_css(css_selector)
  script = "document.querySelector('#{css_selector}').scrollIntoView(true);"
  Capybara.current_session.evaluate_script(script)
end

And call before clicking the element ex: scroll_to_css ".css_selector"

  • Related