【问题标题】:How do i click this button in capybara (using 'ID' or 'Xpath' selector)如何在水豚中单击此按钮(使用“ID”或“Xpath”选择器)
【发布时间】:2017-03-11 20:08:11
【问题描述】:

请帮我解决这个问题

我有一个类似 Capybara 的按钮:

<li id="main-menu-button" data-radium="true" style="flex: 0 0 auto; padding:   0px; box-sizing: border-box; color: rgb(158, 144, 212); display: flex; margin: 5px; border-radius: 5px; width: 50px; height: 50px; flex-flow: row nowrap; justify-content: center; position: relative; transition: background-color 100ms ease-out;">
  <img src="/assets/images/branding/reachify-r-logo-white.png" alt="Logo" data-radium="true" style="width: 50px; height: 50px; padding: 10px; box-sizing: border-box; border-radius: 4px; background-color: rgba(0, 0, 0, 0.2);">
</li>

我尝试过: click_button "主菜单按钮" 和 find_button("主菜单按钮").click

但它给出了错误:

 Unable to find button "Organization" 
  (Capybara::ElementNotFound)

【问题讨论】:

  • 你会显示按钮的 html 吗?

标签: ruby testing automation cucumber capybara


【解决方案1】:

它不是按钮(或输入类型=按钮)元素,因此 click_button 和 find_button 不起作用。你只需要这样做

find('#main-menu-button').click

【讨论】:

  • 感谢您的回答。当我这样做时它显示:无法找到 css "#main-menu-button" (Capybara::ElementNotFound) ./features/step_definitions/login.rb:18:in /^I click Organization button$/' features/login.feature:8:in 然后我点击组织按钮'
  • @ArturAbdullin 然后你试图点击的东西没有你的示例按钮(主菜单按钮)的 id,根本不在页面中,或者不是t 在页面上可见,因为它是一个 li 元素,是下拉列表的一部分还是需要先单击其他内容或将鼠标悬停在其他内容上才能显示的内容?
  • 这是一个按钮元素。 Screen Shot 2016-10-28 at 3.26.42 PM.png
  • @ArturAbdullin 您询问了如何单击您在问题中发布的
  • 元素。那不是
猜你喜欢
相关资源
最近更新 更多
热门标签