我可以在Tritium中使用CSS选择器来移动/复制元素吗?

时间:2013-06-25 19:42:52

标签: moovweb tritium

我正在尝试将元素复制到Tritium中的给定CSS选择器。

Tritum Spec将copy_to的签名列为:

copy_to(Text %xpath)

http://tritium.io/simple-mobile/1.0.224#Node.copy_to(Text%20%25xpath)

我正在尝试:

copy_to(  CSS_SELECTOR )

例如:

copy_to("#header")

我似乎无法让它发挥作用。

以下是Tritium Tester网址:http://tester.tritium.io/4193cf46a239b4ff440cf1b4c36fb703cd22a5a4

1 个答案:

答案 0 :(得分:5)

不幸的是,由于CSS选择器在Tritium中的工作方式,这将无效。

根据规范,CSS选择器被转换为XPath本地搜索,这意味着它们是作用域。

html() {
  $("/html") {
    $$("#header > img") {
      add_class("logo")
    }
    $$("#content") {
      $("./div[@id='courses']"){
        $$("a") {
          attribute("href", "http://console.moovweb.com/learn/training/getting_started/generate")
        }
        copy_to(css('#header'), "before")
      }
    }
  }
}

在您的示例中,您的copy_to功能属于$("./div[@id='courses']")范围,因此无法在其中找到div#header

您必须使用这样的XPath选择器:copy_to("/html/body/div[@id='header']","before")

见这里:http://tester.tritium.io/5f0ae313a4f43038ee4adeb49b81236bfbc5f097

相关问题