I am revisiting a page to create a new record instead of editing a record and I need to ensure that all the field values have been cleared out. (the page is shared between the different actions so I need to make sure the right action produces the right result).
How can I assert that all input fields are clear from data after reset (selenium-ruby-cucumber)

  • Seems like a good question which I've attempted to improve despite close squad mafia May 25 '18 at 0:04
  • How is this question 'unclear' ? This question is like the definition of clarity May 25 '18 at 9:47

Step 0. Set up Webdriver.

require 'rubygems'  
require 'selenium-webdriver'  
driver = Selenium::WebDriver.for :chrome  

Step 1. Set a variable for finding values found_values= false
Step 2. Get an array of all the input elements inputs= driver.find_elements('input')

# all('input') if using Capybara btw 

Step 3. Iterate through them, e.g.

inputs.each |field| do
  field.value <> '' && found_values= true
  break if found_values

Step 4. expect(found_values).to be false


irb(main):001:0> a=2 && b=3
=> 3
irb(main):002:0> p b
=> 3
  • 1
    Hi Michael! How should your pseudo-code be treated? The line inside "do..end" looks like a pure logical expression (except "break") representing some boolean result, however "do" implies some action taken. It seems here is a mix of conditions, assigning value to a variable and breaking the loop, however that is not obvious.
    – Alexey R.
    May 24 '18 at 20:13
  • 1
    Hi @AlexeyR. Thanks. Updated a bit,. The && will get found_values set to true based on condition. I moved the break to the next link based on found_values value May 24 '18 at 23:47
  • What if i want to assert without capybara? May 27 '18 at 6:45
  • that is just about using all. Without capybara use find_elements as shown May 27 '18 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.