[英]In Tritium, what are the differences between CSS and XPath selectors?
[英]Can I use CSS selectors in Tritium for moving/copying elements?
我正在嘗試將元素復制到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 URL: http : //tester.tritium.io/4193cf46a239b4ff440cf1b4c36fb703cd22a5a4
不幸的是,由於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.