小编Far*_*ooq的帖子

如何使用Capybara选择下拉选项

我正在尝试使用Capybara(2.1.0)从下拉菜单中选择一个项目.

我想按编号选择(意思是选择第二个,第三个等选项).

我用Google搜索疯狂尝试各种各样的东西,但没有运气.

我可以通过使用值来选择它:

 find("option[value='4c430d62-f1ba-474f-8e8a-4452c55ea0a8']").click
Run Code Online (Sandbox Code Playgroud)

但我不想使用那种方法b/c值会改变,这将使我的测试变得脆弱.

下拉列表的HTML是:

<td class="value">
    <select name="organizationSelect" id="organizationSelect" class="required">
     <option value="NULL">Choose...</option>
     <option value="4c430d62-f1ba-474f-8e8a-4452c55ea0a8">&nbsp;Institution1</option>
     <option value="e1a4efa7-352d-410a-957e-35c8a3b92944">&nbsp;Institution / test</option>
    </select>
</td>
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

  option = find(:xpath, "//*[@id='organizationSelect']/option[2]").text  
  select(option, :from => organizationSelect)
Run Code Online (Sandbox Code Playgroud)

但它会导致此错误:

Ambiguous match, found 2 elements matching option "Institution" (Capybara::Ambiguous)
Run Code Online (Sandbox Code Playgroud)

那么如何从下拉列表中选择第一个,第二个,第三个等选项(使用Capybara)?

ruby capybara selenium-webdriver

118
推荐指数
5
解决办法
9万
查看次数

包含安装 PEAR/PHPUnit 的路径问题

我正在关注这个http://www.newmediacampaigns.com/page/install-pear-phpunit-xdebug-on-macosx-snow-leopard来安装 PEAR/PHPUnit。我在包含路径方面遇到了问题。

一些背景资料:

Farooqs-MacBook-Pro:bin fyousuf$ which php
/usr/bin/php

Farooqs-MacBook-Pro:bin fyousuf$ which pear
/usr/local/bin/pear

Farooqs-MacBook-Pro:bin fyousuf$ which phpunit
/usr/local/bin/phpunit
Run Code Online (Sandbox Code Playgroud)

我认为我搞砸的部分是我上面发布的链接中的“更新 PHP 包含路径”。

这是我的 php.ini 文件中的内容:

    ; UNIX: "/path1:/path2"
    ;include_path = ".:/php/includes"
    include_path = ”/usr/local/bin/PEAR:/php/includes”
    ;
    ; Windows: "\path1;\path2"
    ;include_path = ".;c:\php\includes"
    include_path = ”/usr/local/bin/PEAR:/php/includes”
    ;
    ; PHP's default setting for include_path is ".;/path/to/php/pear"
    ; http://php.net/include-path`
Run Code Online (Sandbox Code Playgroud)

当我尝试使用 phpunit 运行 Selenium 测试时,出现此错误:

   phpunit functions.php

   PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such            
   file or directory in /usr/local/pear/share/pear/PHPUnit/Autoload.php on line 64 …
Run Code Online (Sandbox Code Playgroud)

php selenium pear phpunit

5
推荐指数
1
解决办法
1万
查看次数

无法找到 Capybara 的复选框

无法找到 Capybara 的复选框。

这是 HTML:

<div class='check-group'>
 <div class='checkbox'>
   <input type="checkbox" name="accepts_fcra" id="accepts_fcra" value="1" />
   <label for="accepts_fcra"><span>Some text <a title="FCRA" target="_blank" href="https://www.google.com/fcra">FCRA</a> some text.</span></label>
 </div>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我想用 ID“accepts_fcra”检查复选框。

我尝试了很多东西,但几乎都返回相同的东西:“无法找到(用于查找复选框的方法)”

一些尝试:

check("#accepts_fcra")
Capybara::ElementNotFound: Unable to find checkbox "#accepts_fcra"

find("#accepts_fcra").set true
Capybara::ElementNotFound: Unable to find css "#accepts_fcra"

within("div.checkbox") do
  find(:xpath, "//input[@id='accepts_fcra']")
end
Capybara::ElementNotFound: Unable to find xpath "//input[@id='accepts_fcra']"
Run Code Online (Sandbox Code Playgroud)

但是checkbox上面的2个类,“.check-group”和“.checkbox”找到了,只是没有找到checkbox。想法?

checkbox visibility capybara selenium-webdriver

3
推荐指数
1
解决办法
4495
查看次数

使用Capybara和Xpath时无法悬停并单击按钮

我正在尝试使用Capybara单击一个按钮.我尝试了所有我能想到的组合,但没有运气.试图点击"删除"链接.只有当您将鼠标悬停在表格中的行上时,才会显示删除链接.

这是HTML:

    <tbody>
    <tr class="even" id="informal_6">
     <td class="columnOrganizationNameColumnValue" id="informal_7">

       <div>
         <a id="showLink_0" title="Organization Details" class="viewLink">
           Institution / Automation
         </a>
       </div>

       <div class="gridMenuDescription">
          &nbsp;
       </div>

       <div class="gridMenu">
           <a id="gridMenuDirectLink_1" title="Edit Organization" class="gridMenuItem">
             edit
           </a>

           <a id="gridMenuDirectLink_2" class="gridMenuItem delete">
             delete
           </a>
       </div>
     </td>

      </tbody>
Run Code Online (Sandbox Code Playgroud)

我想注意一下,"gridMenu"div,当你使用Firebug将鼠标悬停在它上面时,它转向:

       <div class="gridMenu hover gridMenuShow">
Run Code Online (Sandbox Code Playgroud)

我试过的一些事情,但没有运气:

    find(:xpath, '//*[(@id = "gridMenuDirectLink_2")]').click

    find("#informal_6").find("#informal_7").find(".gridMenu.hover.gridMenuShow").find(".gridMenuItem.delete").click
Run Code Online (Sandbox Code Playgroud)

建议?

xpath capybara selenium-webdriver

1
推荐指数
1
解决办法
2051
查看次数