2013-06-25 46 views
2

我想將元素複製到Tritium中給定的CSS選擇器中。我可以在Tritium中使用CSS選擇器來移動/複製元素嗎?

的Tritum規格列出了簽名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") 

我斜面似乎得到這個工作。

這裏是氚測試網址:http://tester.tritium.io/4193cf46a239b4ff440cf1b4c36fb703cd22a5a4

回答

5

不幸的是,這是行不通的,因爲的方式CSS選擇器中的氚工作。

根據規範,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

相關問題