YusukeIwaki / playwright-ruby-client

Playwright client for Ruby
https://playwright-ruby-client.vercel.app/
MIT License
336 stars 34 forks source link

How do I blur an element nicely? #289

Closed mhenrixon closed 7 months ago

mhenrixon commented 7 months ago

Usecase / What to achieve

I have some calculations that run on blur (lost focus). I want a concise way to blur that element by filling it in.

Question

I found this old code on the internet:

def fill_in_then_blur(locator, with:)
  fill_in(locator, with:)
  find_field(locator).native.send_keys :tab # Tab away from the element to trigger a blur event.
end

I also tried page.keyboad.press("Tab") but it seems that didn't work either. Love your work, appreciate your assistance. Cheers.

YusukeIwaki commented 7 months ago

@mhenrixon Hi, Locator#blur would be the best way for it.

YusukeIwaki commented 7 months ago

Feel free to reopen the issue if needed.

mhenrixon commented 7 months ago

@YusukeIwaki not sure what you are refering to but:

The following works:

def fill_in_then_blur(locator, with:)
  find_by_id(locator).set(with).send_keys :tab
end

The following does not:

def fill_in_then_blur(locator, with:)
  find_by_id(locator).set(with).blur
end

I thought the locator would be the result of the find. What am I missing?

  1) Cars can add and sell cars
     Failure/Error: find_by_id(locator).blur

     NoMethodError:
       undefined method `blur' for an instance of Capybara::Node::Element

     [Screenshot Image]: tmp/capybara/screenshots/failures_r_spec_example_groups_cars_can_add_and_sell_cars_553.png