Filling out form with Selenium works on Chrome but not Firefox

牧云@^-^@ 提交于 2019-12-24 21:45:07

问题


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!!


回答1:


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"


来源:https://stackoverflow.com/questions/50197699/filling-out-form-with-selenium-works-on-chrome-but-not-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!