Ruby on Rails Thursday, May 28, 2015



On Wednesday, May 27, 2015 at 7:11:54 PM UTC+2, Rafael s wrote:

Currently I'm trying use a statement IF (If a button appears in the page, then run the IF), see the method Login in the system:

If the button doesn't appear in the page, I would like to run the next method Remove and add new expense

require "selenium-webdriver"  require "rspec"  require "rspec/expectations"    describe "#Add simple expense and after add a receipt", :suitee => true do    before(:all) do    @driver = Selenium::WebDriver.for :chrome    @base_url = "http://sitetest.com"    @driver.manage.window.maximize  end    it "Login in the system" do    @driver.get(@base_url)    @driver.find_element(:id, "user_email").send_keys "raf...@gmail.com"    @driver.find_element(:id, "user_password").send_keys "123456"    @driver.find_element(:name, "commit").click      if(@driver.find_element(:css, ".btn.btn-lg.btn-success.btn-block").displayed?)          @driver.find_element(:css, ".btn.btn-lg.btn-success.btn-block").click          @driver.find_element(:css, ".introjs-button.introjs-skipbutton").click          @driver.find_element(:css, ".i.i-pencil").click      end  end    it "Remove and add new expense" do    begin       while(@driver.find_element(:css, ".i.i-pencil.icon").displayed?)       button = @driver.find_element(:id, "expense-bulk-select")       @driver.action.click(button).perform        delete = @driver.find_element(:id, "delete-multi-btn")       @driver.action.click(delete).perform       waitDisplayModal = Selenium::WebDriver::Wait.new(:timeout => 10)       waitDisplayModal.until {@driver.find_element(:class => "bootstrap-dialog-footer-buttons")}       @driver.find_element(:xpath, "//div[3]/div/div/button[2]").click        sleep 3    end   rescue Selenium::WebDriver::Error::NoSuchElementError      @driver.find_element(:id, "current_expense_merchant").send_keys "Taxi to work"      @driver.find_element(:id, "current_expense_amount").send_keys "50"     @driver.find_element(:id, "button-add-expense").click     waitDisplayIconTrash = Selenium::WebDriver::Wait.new(:timeout => 20)     waitDisplayIconTrash.until {@driver.find_element(:css => ".i.i-pencil.icon")}   end  end     after(:all) do    @driver.quit      end  end


My problem: When I run this script, appears this in my console:

Failure/Error: if(@driver.find_element(:css, ".btn.btn-lg.btn-success.btn-block").displayed?)   Selenium::WebDriver::Error::NoSuchElementError:     no such element       (Session info: chrome=42.0.2311.135)       (Driver info: chromedriver=2.9.248304,platform=Linux 3.13.0-24-generic x86_64)


That is, the IF is not working as I would like. How can I fix it?

CHeers


You can check the displayed page by adding the below statement just before your IF statement:

save_and_open_page

One more thing is to check if you enable selenium ddriver in your rspec config file:

Capybara.default_driver = :selenium




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/db80df4c-a39b-4f00-9aec-fb24c7d6d142%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment