• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

S-IDE では操作対象の要素を xpath で指定することができる。

例:xpathの明示
コマンド対象
clickxpath=//h2/a

対象要素を特定するこの機能は Element Locator と呼ばれ、 Selenium Core で提供されている。

   1  BrowserBot.prototype.findElement = function(locator, win) {
   2      var element = this.findElementOrNull(locator, win);
   3      if (element == null) throw new SeleniumError("Element " + locator + " not found");
   4      return element;
   5  }
(selenium-core-1.0.1/core/scripts/selenium-browserbot.js)

従って、S-IDE の対象指定以外での場所、 例えば自作関数内や getEval の中などで使いたい場合には、 上記の findElement を直接呼び出すとよい。

HP2703/2842
MP1413/1413

   1  function isHpFull(percent) {
   2    var path = '//tr[0]/td[1]';
   3    var hp   = selenium.browserbot.findElement(path).split('/');
   4    var hp1  = parseInt(hp[0]);
   5    var hp2  = parseInt(hp[1]);
   6    return ((hp1 * 100 / hp2) > percent);
   7  }

例:HPが90%以上ある場合は宿屋に入らない
コマンド対象
gotoIfisHpFull(90)skip_inn
clicklabel=宿屋
labelskip_inn

関連として、Selenium 環境ではない状態の Mozilla で xpath を扱うには、 document.evaluate が便利である。

   1  function xpath2text(path) {
   2    var result = document.evaluate(path, doc, null, 7, null);
   3    var item = result.snapshotItem(0);
   4    return item.innerHTML;
   5  }

参考

  • https://developer.mozilla.org/ja/Introduction_to_using_XPath_in_JavaScript
posted by Png maiha on Fri 25 Sep 2009 at 21:50
Contents
Selenium IDE で xpath
Comments
maiha: 追記)対応は約1営業日でした。チームの忙しさに応じて変動するとは思いますが、大体の目安情報とい... '10-4
maiha: なるほど。rails のログから実行したクエリを抜き出したいと思うことがよくありまして。 あ... '10-3
winebarrel: レポートありがとうございます。 削除できない件は修正しました。 SQLのparserはTC/... '10-2
maiha: なるほど。ありがとうございます! '10-2
ursm: Haml 2.2 以降はどこでも式展開が使えるようになったので、== は意味がなくなりました。... '10-2
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ