Search code examples
rubyselenium-webdriverwatirselenium-firefoxdriver

Filling out form with Selenium works on Chrome but not Firefox


I'm trying to fill out a textarea using Selenium and ruby in Firefox, but for some reason, the code below doesn't work. When I switch the same script to Chrome driver though, it does work.

browser.textarea(:placeholder => "Add a comment…").set "#{randomly_chosen_comment}"

On firefox, I get this error:

/Users/miajohansson/.rvm/gems/ruby-2.2.4/gems/watir-6.10.3/lib/watir/elements/element.rb:623:in `raise_present': element located, but timed out after 30 seconds, waiting for #<Watir::TextArea: located: true; {:placeholder=>"Add a comment…", :tag_name=>"textarea"}> to be present (Watir::Exception::UnknownObjectException)
    from /Users/miajohansson/.rvm/gems/ruby-2.2.4/gems/watir-6.10.3/lib/watir/elements/element.rb:669:in `rescue in element_call'
    from /Users/miajohansson/.rvm/gems/ruby-2.2.4/gems/watir-6.10.3/lib/watir/elements/element.rb:680:in `element_call'
    from /Users/miajohansson/.rvm/gems/ruby-2.2.4/gems/watir-6.10.3/lib/watir/user_editable.rb:11:in `set'
    from instabot.rb:68:in `block (2 levels) in <main>'
    from instabot.rb:36:in `each'
    from instabot.rb:36:in `block in <main>'
    from instabot.rb:35:in `loop'
    from instabot.rb:35:in `<main>'

I've been working on this for many hours and I can't seem to figure out why it's not working. I need to get it to work on Firefox. Any help is very appreciated!!


Solution

  • I can't reproduce your issue; it is working for me without using the deprecated driver. Are you using the latest Firefox & geckodriver version?

    One issue is that the dots are not periods, but different unicode; this will work with the latest geckodriver just fine:

    browser.textarea(placeholder: /Add a comment/).set "#{randomly_chosen_comment}"
    

    Or, because that is the first textarea on the page, you can just do:

    browser.textarea.set "foo"