Pregunta

I am trying to copy an element to a given CSS selector in Tritium.

The Tritum Spec lists the signature for copy_to as:

copy_to(Text %xpath)

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

I am trying to do:

copy_to(  CSS_SELECTOR )

For e.g:

copy_to("#header")

I cant seem to get this to work.

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

¿Fue útil?

Solución

Unfortunately, that won't work because of the way CSS selectors work in Tritium.

According to the spec, CSS selectors are converted into XPath local searches, which means they are scoped.

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.

You'll have to use an XPath selector like this: copy_to("/html/body/div[@id='header']","before")

See here: http://tester.tritium.io/5f0ae313a4f43038ee4adeb49b81236bfbc5f097

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top