1
votes

I'm new to automation, sorry if the title is not appropiate.

I have Ruby, Devkit, gem json, cucumber, capybara, selenium-webdriver, rspec installed following the guide http://www.swtestacademy.com/ruby-cucumber-and-capybara-on-windows/

However I cannot locate an element using a full xpath (checked and verified with xpath plugin and developer tool), my action is:

page.find(:xpath, "my_xpath").send_keys(yyy)

and I got: Unable to find visible xpath

I also tried:

page.findElement(By.xpath("my_xpath")).send_keys("ori_pw")

and I got: uninitialized constant By (NameError)

And I would like to try using watir, I have installed gem watir, watir-webdriver. and added require 'watir' into my env.rb then I try:

page.input(:name => "xxx").set(yyy)

But I get: undefined method `input' for # (NoMethodError)

May I have some suggestions please? Thanks.

=============================================Edit#1

My env.rb now looks like this:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'rspec'
require "selenium-webdriver"
require 'watir'
require 'cucumber'

Selenium::WebDriver::Firefox::Binary.path='C:\Program Files\Mozilla Firefox\firefox.exe'

Capybara.run_server = false
#Set default driver as Selenium
Capybara.default_driver = :selenium
#Set default selector as css
Capybara.default_selector = :cs

#Syncronization related settings
module Helpers
    def without_resynchronize
        page.driver.options[:resynchronize] = false
        yield
        page.driver.options[:resynchronize] = true
    end
end
World(Capybara::DSL, Helpers)

How can I disable capybara and set watir properly? Sorry that I have no technical background...

Thomas, Yes the element is visible, HTML screenshot Actually I will be setting value to these 3 password fields. The xpath I'm trying is:

/html/body[@class='modal-open']/app-root/div[@id='wrapper']/app-navigation/user-change-password/div[@id='myModal']/div[@class='modal-dialog modal-lg']/div[@class='modal-content']/div[@class='modal-body']/form[@class='ng-pristine ng-invalid ng-touched']/fieldset[@class='form-horizontal']/div[@class='form-group'][1]/div[@class='col-sm-7']/input[1]

(at the end I use avoid using class as I see the class name different sometimes) Thanks. =============================================Edit#2

The problem now shift to chromedriver. Double clicking it able to show

Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 9515
Only local connections are allowed.

But enter chromedriver on cmd will show Chromedriver.exe has stopped working.

1
Is the element you're looking for actually visible on the page? (showing the actual XPath you are requesting and relevant HTML would help) and you can't mix capybara and watir they each maintain their own sessions separately.Thomas Walpole

1 Answers

1
votes

The reason it's not working for you is due to an unfortunate bug in geckodriver/firefox - which is probably also going to affect watir - whereby it assumes any element with a hidden attribute is actually non-visible (if the display style is set to anything other than default it actually overrides the hidden attribute but not as far as selenium is concerned). This is affecting you because of the hidden attribute on the element div#myModal which makes selenium think the entire modal is non-visible - https://github.com/mozilla/geckodriver/issues/864. If you swap to testing with Chrome instead the issue will go away.

Additionally using XPaths as specific as you show is a terrible idea and will lead to highly fragile tests. If you swap to Chrome (Capybara.default_driver = :selenium_chrome) you'd be much better off just doing something like

page.fill_in('Original Password', with: 'blah')

or

page.find('input[name="originalPassword"]`).set('blah')

One final point, the :resynchronize option went away a long time ago, you might want to find a more up to date guide to follow