Ruby / automation beginner here - I'm trying to get and store an email address from a webpage using the element id, but am getting the error undefined local variable or method 'customer_email_address' for main:Object (NameError) when executing it.

The aim is to store the email address, and then login to our back office to search for it - so I think I'm looking for a storeValue or getValue equivalent?

This is the page:

@driver.find_element(:id, "customer_email_address")

a = driver.find_element(id: 'customer_email_address')

replace double quotes with single quotes and there is not getText in ruby but text

read this :


//working syntax

 require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
  # Navigate to URL
  driver.get 'https://google.com'

  # Get search box element from webElement 'q' using Find Element
  search_bar = driver.find_element(id: 'customer_email_address').text

  # Perform action using WebElement
  search_bar.send_keys 'Webdriver'
  • Thanks for your response. I was getting the same results with both single and double quotes, but have switched them to single as it looks like it's best practice? I've also edited the question - I'm trying to get (like copy or store) the email address and not just find the element. My apologies, I should have made it clearer. – trashpanda Feb 27 '20 at 15:02
  • Did you try the working syntax? to get Text , you should use element.text . In ruby get text is a property and not a method – PDHide Feb 27 '20 at 15:07
  • try this syntax driver.find_element(id: 'customer_email_address').text – PDHide Feb 27 '20 at 15:08
  • Yup, that works great - but does driver.find_element(id: 'customer_email_address').text not just find the element? – trashpanda Feb 27 '20 at 15:17
  • 1
    Hey @PDHide, thanks for your help yesterday - I've gone with a different solution which avoids having to find and store the value. Instead, I'm defining it at the start of the script with email_address = "trash.panda+#{Time.now.to_i}@searchingyourbins.com", and then calling it when needed with .send_keys(email_address) and #{email_address} :) Happy to accept your answer though as I'm sure it'll be correct for someone who's better with Ruby! – trashpanda Feb 28 '20 at 9:31

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.