简体   繁体   English

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

[英]Can I use CSS selectors in Tritium for moving/copying elements?

I am trying to copy an element to a given CSS selector in Tritium. 我正在尝试将元素复制到Tritium中的给定CSS选择器。

The Tritum Spec lists the signature for copy_to as: Tritum Spec列出了copy_to的签名为:

copy_to(Text %xpath)

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

I am trying to do: 我正在尝试做:

copy_to(  CSS_SELECTOR )

For eg: 例如:

copy_to("#header")

I cant seem to get this to work. 我似乎无法使它正常工作。

Here is the Tritium Tester URL: http://tester.tritium.io/4193cf46a239b4ff440cf1b4c36fb703cd22a5a4 这是Tritium Tester URL: http : //tester.tritium.io/4193cf46a239b4ff440cf1b4c36fb703cd22a5a4

Unfortunately, that won't work because of the way CSS selectors work in Tritium. 不幸的是,由于CSS选择器在Tritium中的工作方式,因此无法使用。

According to the spec, CSS selectors are converted into XPath local searches, which means they are scoped. 根据规范,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")
      }
    }
  }
}

In your example, your copy_to function is in the scope of $("./div[@id='courses']") , so it won't find the div#header in there. 在您的示例中,您的copy_to函数在$("./div[@id='courses']") ,因此在其中找不到div#header

You'll have to use an XPath selector like this: copy_to("/html/body/div[@id='header']","before") 您必须使用这样的XPath选择器: copy_to("/html/body/div[@id='header']","before")

See here: http://tester.tritium.io/5f0ae313a4f43038ee4adeb49b81236bfbc5f097 看到这里: http : //tester.tritium.io/5f0ae313a4f43038ee4adeb49b81236bfbc5f097

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM