Reputation: 163
I am trying to test a UI that has the ability to drag and drop. All im looking to do is to drag an element to another element on the page. The code is below.
it 'should drag and drop' do
draggable = @driver.find('//*[@id="2"]').first
droppable = @driver.find('//*[@id="dropmembers4"]').first
draggable.drag_to(droppable)
@driver.find('//div[contains(., "Dropped!")]').should_not be_nil
end
Currently im getting an error:
Failure/error: draggable = @driver.find('//*[@id="2"]').first
No method error: undefined method 'find' for nil:NilClass
Any help would be great.
Thanks
Upvotes: 3
Views: 1299
Reputation: 7776
The @driver
variable does not exist, that mean the initialization is not working. Here's the minimal initialization code:
$ [sudo] gem install selenium
$ selenium install
And the code for using it:
require 'selenium'
@driver = Selenium::WebDriver.for(:chrome)
And if you're using bundler to define dependencies, you should run:
$ bundle install
And then this code:
require 'rubygems'
require 'bundler/setup'
require 'selenium'
@driver = Selenium::WebDriver.for(:chrome)
Upvotes: 1