【问题标题】:Automation using Watir button elements使用 Watir 按钮元素的自动化
【发布时间】:2015-11-05 18:31:00
【问题描述】:

所以我一直在用 Ruby 试验 Watir 自动化脚本。我尝试过使用不同的网站,例如 Twitter、Gmail 和 Yahoo。问题是:我能够打开浏览器、登录并进入主页。在所有这些上,无论是撰写新电子邮件还是推文,每次我使用适当的 ID 或类选择它时,它都会在终端中引发这样的错误......

.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:533:in assert_element_found': unable to locate element, using {:title=>"compose", :tag_name=>"button"} (Watir::Exception::UnknownObjectException) from /Users/xxx/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:505:inassert_exists' 来自 /Users/xxx/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:114:in click' from yahoo_mail.rb:18:incompose_email' 来自 yahoo_mail.rb:27:in `'

我的问题是,是否存在您无法使用 Watir 自动化单击或选择的元素?

编辑:我如何才能更具体地做到这一点?在登录后撰写任何内容时,我似乎在 Yahoo、Gmail 和 Twitter 上得到了相同的结果。那么我该如何点击这个按钮呢?

button id="global-new-tweet-button" type="button" class="js-global-new-tweet js-tooltip btn primary-btn tweet-btn js-dynamic-tooltip" data-placement= “底部” data-component-term="new_tweet_button">

【问题讨论】:

    标签: ruby selenium automation watir


    【解决方案1】:

    撰写按钮的 HTML 基本上如下(注意:已删除 id 属性):

    <button tabindex="0" data-action="compose" title="Compose" class="btn btn-compose">
    

    您的堆栈跟踪表明您正在使用此定位器:

    {:title=>"compose", :tag_name=>"button"}
    

    如果您将:title=&gt;"compose" 更改为:title=&gt;"Compose",您应该在做生意。

    【讨论】:

    • 我真的很兴奋,因为我希望这会是答案,因为这很有意义。但是在这种情况下,情况并非如此,这是我试图点击的 html...
    【解决方案2】:

    你试过下面的代码吗?

    button(id:'global-new-tweet-button').when_present.click

    也许您在点击按钮时没有检查它是否已经出现在页面上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多