![](/img/trans.png)
[英]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.