Matthew Helfgott
Matthew Helfgott

Reputation: 159

undefined method 'find_element' for Selenium::WebDriver:Module when using method from another module

Hello I am new to programming working on Selenium using Ruby and I'm having some trouble. I am trying to call a method from a class in another module so I can create a sort of method library and every time I am returned the error NoMethodError: undefined method 'find_element' for Selenium::WebDriver:Module I have require_relative "LeadForm" to require the other module and the code works properly when I put the method directly into the class I'm using it in but I would really like to just have it written once because this is something I will be using a lot.

The code is

def self.progCNA

Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "area_of_study")).select_by(:text, "Health & Medical / Nursing") Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "concentration")).select_by(:text, "Nursing Assistant (CNA)")

end

and when I call it in the the class that runs the test I put

LeadForm.progCNA

and it appears to recognize and run the method but then the method errors out.

Any help would be greatly appreciated as this has been a source of a lot of frustration and I can't for the life of me find a solution online. I have looked up, down and sideways. If you require any more information from me please let me know and I will get it to you as soon as possible! Thank you very much.

I'm using Windows 7 Pro sp1 JetBrains RubyMine 4.5.3 Ruby 1.9.3 selenium-webdriver 2.25.0

Upvotes: 1

Views: 5299

Answers (2)

Chetan Patel
Chetan Patel

Reputation: 13

WebElement element = driver.find_Element(:xpath=>regisCodePath)
String passcode=element.getAttribute('value');

Upvotes: 0

grumpasaurus
grumpasaurus

Reputation: 712

If I understand the situation, I think you have a variable scope issue.

If you want to keep your class structure the way it is, I would update your method with...

def self.progCNA(driver)

Selenium::WebDriver::Support::Select.new(driver.find_element(:name, "area_of_study")).select_by(:text, "Health & Medical / Nursing") Selenium::WebDriver::Support::Select.new(driver.find_element(:name, "concentration")).select_by(:text, "Nursing Assistant (CNA)")

end

... and call it with

LeadForm.progCNA(@driver)

You could... make a $driver global instead...

Upvotes: 2

Related Questions