黄瓜/水豚从特定类别选择按钮? [英] Cucumber/Capybara Selecting Button from Specific Class?

查看:271
本文介绍了黄瓜/水豚从特定类别选择按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了一个问题,我想点击一个按钮...不幸的是有相同的文字(IE有两个按钮的页面上相同的文本,基本上一个保存按钮)

So i've ran into an issue, im trying to click a button...which unfortunately has the same text (IE there are 2 buttons on the page which the same text, basically a save button)

假设按钮文本只是保存。

Lets pretend the button text is just "Save".

我注意到他们有不同的类。

I did notice that they had different classes.

<button data-action="submit" class="btn btn-primary btn-save">Save</button>

,而其他按钮是:

<button name="button" type="submit" class="btn btn-primary set-right">
      <i class="glyphicon glyphicon-floppy-disk"></i> Save
</button>

我知道glypicon只是一个图标集....但他们似乎都属于同一个类?但有不同的类名? (对不起,我不熟悉Rails)

I know glypicon is just an icon set....but they both seem to belong to the same class? but have different class names? (Sorry im not familiar with Rails)

这不是真正的问题,我选择,因为他们都有相同的功能。我看到你可以使用xpath?但是不是我们应该使用css选择器或现在的东西?

It doesn't honestly matter which one I select as they both have the same function. I've seen where you can use xpath? but aren't we supposed to use css selectors or something now? (As in thats the newest way?) I may be wrong....

我可以使用类似的东西:

Could I use something like:

find(:xpath, '//button[@class="btn-save"]').click

我试图避免rails只有解决方案,因为不是所有的网站,我测试是基于轨道。

Im trying to avoid "rails" only solutions, as not all the websites I test on are rails based.

推荐答案

您有各种可能性:

1)按

find(button.btn.btn-primary.btn-save).click

2)按 css selector xpath (您可以使用Google Chrome复制它们:右键 - >检查 - >右键单击您的元素 - >复制css或xpath)

2) Find the button by its css selector or xpath (you can copy them using Google Chrome: right click -> Inspect -> right click on your element -> copy css or xpath)

find(:css, "your button css selector").click

find(:xpath, "your button xpath").click

这篇关于黄瓜/水豚从特定类别选择按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆