1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Ruby problem

Discussion in 'General Programming Chat' started by fun4uoc, Mar 15, 2015.

  1. fun4uoc

    fun4uoc Supreme Member

    Joined:
    Dec 25, 2007
    Messages:
    1,200
    Likes Received:
    1,042
    Location:
    ☆ ♔ ☆ ♔ ☆ ♔ ☆
    Just started playing around with Ruby and have run into an issue.

    I have it hardcoded to pull a random name and store it in a variable.

    Code:
    firstname = "Becky","Mary","Anabel","Geneva","Margart","Christina","Diane"
    
    first = firstname.sample(1)
    
    wd.find_element(:id, "first_name").send_keys "#{first}"
    

    This works fine when checking with puts, however, when I run it it enters this in the field. ["Joyce"]

    If I just do it like this it works fine.
    Code:
    wd.find_element(:id, "first_name").send_keys "Joyce"
    
    I've tried pulling names from a txt and csv file with the same results. Tried several methods i've found on google to remove the [""] but they all caused the bot to not even run.

    Any ideas?

    Thanks
     
    Last edited: Mar 15, 2015
  2. ac3rpr0

    ac3rpr0 Newbie

    Joined:
    Mar 15, 2015
    Messages:
    15
    Likes Received:
    2
    your var "first" is an array with just one value! To get the string inside of this array you have to use either "#{first.first}" or "#{first[0]}"
     
    • Thanks Thanks x 1
  3. fun4uoc

    fun4uoc Supreme Member

    Joined:
    Dec 25, 2007
    Messages:
    1,200
    Likes Received:
    1,042
    Location:
    ☆ ♔ ☆ ♔ ☆ ♔ ☆
    Doh!!!

    That did it, thanks bud.