gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:59:40 26 4
gpt4 key购买 nike

我正在尝试将元素复制到 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")

我似乎无法让它工作。

这是氚测试仪 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

关于moovweb - 我可以在 Tritium 中使用 CSS 选择器来移动/复制元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17306103/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com