1

以下で詳しく説明するように、jQueryUI公式プラグインによって生成された選択メニューからSeleniumにオプションを選択させるのに苦労しています.Seleniumはメニューを開き、クリックしてアイテムを選択し、メニューを閉じますが、オプションは選択されていません。

セットアップの背景:

  • Selenium IDE Firefox プラグインの使用
  • jQueryUI SelectMenu デモ ページを使用してテストします (コード スニペットが誰もがアクセスできるものであることを確認し、デモ サイトとして selectmenu が少なくとも適切に実装されていることを排除できます)

テスト ソース: http://jqueryui.com/selectmenu/

セレンクリックのspan.ui-selectmenu-textをターゲットにして、ID = ui-id-5の要素をクリックしようとしましたが、うまくいきませんでした。次に、span.speed-button をクリックして、オプションを選択してみました。運もありません。

いずれの場合も、メニューは開いたり閉じたりしますが、元の値が選択されたままです。

しかし、奇妙なことが起こります。Selenium IDE で次の操作を行うと、それが選択されます。

  1. メニューを開くコマンドをダブルクリックします。
  2. コマンドをダブルクリックして、正しい ID 要素を選択します。
  3. 正しい ID 要素を選択するためのコマンドをもう一度ダブルクリックします。

突然、選択したオプションが更新されます。しかし、2 つのクリック コマンドを使用してスクリプトをエンド ツー エンドで実行すると、再び失敗し、ページでデフォルトのオプションが選択されているだけです。

コード:

<tr>
    <td>open</td>
    <td>/selectmenu/</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=span.ui-selectmenu-text</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=ui-id-5</td>
    <td></td>
</tr>

誰かが私を正しい方向、ヒントやヒント、または問題の実際の解決策に向けることができれば、それは素晴らしいことです.

これを投稿する前にSOを検索しましたが、見つけたのは3年前のものだけで、解決策はもう機能しませんでした:

ui selectmenu (jQuery) とセレンを使用してテストする方法

4

2 に答える 2

0

単一の値を選択することだけに関心がある場合は、クリックしてメニューを開かなくても選択できます。実行するだけです: |select|実際の SELECT html 要素のロケータ|必要な値|

これが機能するのは、jQuery.ui.selectmenu が SELECT html 要素を受け取り、それに応じてスタイルを設定するためです。

<tr>
  <td>select</td>
  <td>id=address-state</td>
  <td>label=Alabama</td>
</tr>

ここで、ユーザー入力全体を UI で本当にシミュレートしたい場合は、次のような clickAt コマンドを使用する必要があります。

<tr>
  <td>clickAt</td>
  <td>id=ui-id-1-button</td>
  <td></td>
</tr>

ui-id-1-button は、ページに挿入された jQuery.ui.select の DIV です (DOM 構造を表示するには、Chrome または FF のインスペクターを使用します)。選択するには、通常は ui-id-1-menu の生成された ID を使用する UL を持つ DIV があるページの下部にある DOM を調べます。その中には、ドロップダウン オプションがあり、セレクターを開き、clickAt コマンドを送信します。

user-extensions.js コマンドを使用して、ドロップダウンをスクロールし、ページごとにオプションのスクリーンショットを撮る方法を見つけました。

Selenium.prototype.doScreenshootSelectMenuOptions = function(btnLocator, jsonOptions) {
    /**
     * Capture the jQuery.ui.selectmenu dropdown option values page by page screenshots.
     *
     * @param btnLocator    Element locator for the selectmenu button
     * @param jsonOptions   Options for the command as a JSON string. They are <code>
     *                      {"dropdownLocator":"<optional value>", "fileName":"<optional value>", "extension":"<optional value>"}
     *                      <\code>
     *                      <ul>
     *                          <li>dropdownLocator: Optional element locator for hidden selectmenu options locator. If
     *                          ommited it will be computed from options.dropdownLocator</li>
     *                          <li>fileName: Optional name of the file to use for the screenshot. It will be appended
     *                          with ' pg#' where # is the drop down page number. If omitted the default file name is
     *                          'Dropdown'</li>
     *                          <li>extension: Optional name of the file extension to use for the screenshot. If
     *                          omitted the default extension is '.png'</li>
     *                      </ul>
     */
    LOG.debug("user-extensions: doScreenshootSelectMenuOptions('" + btnLocator + "', '" + jsonOptions + "')");

    var btn = this.browserbot.findElement(btnLocator);
    if(btn.id.indexOf('-button') <= 0) {
        throw new SeleniumError("screenshootSelectMenuOptions: wrong value for 'btnLocator'. It's applied to jQuery.ui.selectmenu drop downs!");
    }

    var options = JSON.parse(jsonOptions);
    if(typeof options.dropdownLocator  === 'undefined') {
        options.dropdownLocator = btn.id.substr(0, btn.id.indexOf('-button')) + '-menu';
    } else if(options.dropdownLocator.indexOf('-menu') <= 0) {
        throw new SeleniumError("screenshootSelectMenuOptions: wrong value for 'jsonOptions.dropdownLocator'. It's applied to jQuery.ui.selectmenu drop downs!");
    }

    options.fileName  = (typeof options.fileName  !== 'undefined') ? options.fileName  : "Dropdown";
    options.extension = (typeof options.extension !== 'undefined') ? options.extension : ".png";
    var ddBtn           = this.browserbot.findElement(btnLocator),
        opts            = this.browserbot.findElement(options.dropdownLocator);
    ddBtn.scrollIntoView();     // Scroll to dropdown so it has room to open downwards
    this.doClickAt(btnLocator); // Open dropdown

    var height          = isNaN(parseInt(opts.style.height)) ? opts.scrollHeight : parseInt(opts.style.height),
        scrollHeight    = opts.scrollHeight,
        pages           = scrollHeight / height,
        level           = utils.screenshoot.getNextLevel();
    if(pages <= 0) {
        throw new SeleniumError("screenshootSelectMenuOptions could not computer the number of dropdown menu pages to screenshoot!");
    }

    // For each dropdown values page(s)
    for(var pgNr = 0; pgNr < pages; pgNr++) {
        var pgHeight = (pgNr * height);
        LOG.debug("user-extensions: screenshootSelectMenuOptions opts.scrollTo('0', '" + pgHeight + "')");
        opts.scrollTo(0, pgHeight);
        this.doScreenshotEntirePage(options.fileName + ' pg' + (pgNr + 1) + options.extension, level);
        ddBtn.scrollIntoView();
    }

    this.doClickAt(btnLocator); // Close dropdown
    utils.screenshoot.resetFromLevel(level);
};

于 2015-04-07T19:49:34.997 に答える