rubygithubwatirsubmit-buttondisable

Ruby / Watir : how to click on a disabled button (Watir::Exception::ObjectDisabledException)


I want to make a program in Ruby that create a github repository. Everything is all right, but when i want to click the button 'create repository' after filling the repository name, nothing happened and the program stop with a timeout error.

This is the html code of the disabled button :

<button type="submit" class="btn btn-primary first-in-line" data-disable-with="Creating repository…" disabled="">
        Create repository
      </button>

And the html code of the enabled button :

<button type="submit" class="btn btn-primary first-in-line" data-disable-with="Creating repository…">
        Create repository
      </button>

And this my ruby program

repo_name = gets.chomp
repo = browser.text_field(id: 'repository_name')
repo.set(repo_name)

browser.driver.manage.timeouts.implicit_wait = 3

create_button = browser.button(type: "submit")
create_button.wait_until(&:enabled?).click

I'am pretty sure that my pb comes that when i'm landing on the page, the button is disabled, and even if i'm filling the repository_name input, my prog can't access to the button.

So do you have a solution about that ? Or maybe do you know if there is an other pb ?

Edit :

When here is the code without the waiting commands :

repo_name = gets.chomp
repo = browser.text_field(id: 'repository_name')
repo.set(repo_name)

create_button = browser.button(type: "submit").click

And when I run it, I'v got a 'Watir::Exception::ObjectDisabledException' error

("element present, but timed out after 30 seconds, waiting for #
<Watir::Button: located: true; {:type=>"submit", :tag_name=>"button"}> to be enabled (Watir::Exception::ObjectDisabledException)"

Solution

  • I think below code might work for you

    browser.text_field(id: 'repository_name').set("repo_name")
    browser.send_keys(:tab)
    

    And as Justin mentioned in his answer, click the create repository button as below:

    browser.button(type: "submit", visible: true).click