Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:40:43+00:00 2026-05-27T20:40:43+00:00

Programming newbie here, about a month in with Ruby. I’m currently playing around with

  • 0

Programming newbie here, about a month in with Ruby. I’m currently playing around with Watir and have a few questions to streamline the automation process of a simple form fill.

Current Code:

# Start Watir
require 'watir-webdriver'
# Open Firefox w/ Watir
browser = Watir::Browser.new :ff
# Visit URL w/ browser
browser.goto("http://website.com")
# Fill in page name field
browser.text_field(:name => "page_name").set "page_name1"
# Fill in password field
browser.text_field(:name => "password").set "static_password"
# Click publish button
browser.button(:value => "Publish").click
# Puts URL
puts browser.url

What I’d like to add on to this is:

  • Loop the process XXX amount of times (do, end?)
  • Pull the page name from an ordered list (array?), don’t use same name twice
  • After the page is published, group & save the page name + URL + password (hash?)

Any guidance on this is much appreciated, I’m not getting too far guessing, I just need a push in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:40:44+00:00Added an answer on May 27, 2026 at 8:40 pm

    Ruby has a wonderful concept called iterables which can help with this.

    First bullet. looping a given number of times, lets say 100 for example. There about 10 different ways to skin this cat, but my favorite is just this

    100.times do
      #code lines to be repeated
    end
    

    Second bullet, which likely changes the approach presuming what you want is to do something once for every line in the array of site names.

    First create your array, then make use of the wonderful .each method to do something with each row of the array. If your array was named page_names then

    page_names.each do |name|
      #code to be repeated, use `name` variable at point you need the value
      browser.text_field(:name => "page_name").set name
    end
    

    This .each method can be used with just about any ‘collection’ of items, which means you can end up doing stuff that looks like this

    pages.each do |page|
      code that does something with page.name
      code that does something with page.password
    end
    

    Third bullet, yep Michael (who I saw just posted an answer) has what I’d have suggested which is a nested hash, although since you are starting with page names, and that’s the part you know, and the URL is something the script is gathering, I’d use the page_name as the key to the outer hash that would let you look up the url and password values for each page name. (I’m presuming in that case you would be doing something like generating the passwwords randomly and thus the need to store them)

    Combining the above with .each it’s important to know that in that case of using .each with hashes, the first thing you get back from .each is the key, and then the value. So if you had an the nested hash discussed above prepopulated with passwords, and keyed on page names, you might do something like this

    pages.each do |page_name, pageinfo|
      browser.goto("http://website.com")
      browser.text_field(:name => "page_name").set page_name
      browser.text_field(:name => "password").set pageinfo[:password]
      browser.button(:value => "Publish").click
      pages[page_name][:url] = browser.url
    end
    

    (given murphy loves me I expect I’ve made some mistake above, which another rubiest will no doubt spot.. fortunately you can edit these answers to fix that stuff later)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pardon the dumb newbie question here; web programming isn't my forte... (blush) I have
I'm a socket programming newbie. Here's a snippet: struct sockaddr_storage client_addr; ... client_addr_size =
Newbie here programming my first app (having made several tutorial apps). I am using
I am a complete Android programming newbie. I have completed some tutorial examples like
Complete newbie to programming :) i am fiddling around with a WordPress theme and
I'm a newbie to iOS programming, I have a project and my requirements are
I'm newbie in Functional Programming. I have a huge neural network with thousands of
This might sound stupid, but I'm seriously a newbie at Android programming. I have
I'm currently learning functional programming in my spare time with Scala, and I have
I'm a newbie into Android programming... Here's what I'm trying to do for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.