我正在 JS 中设计一个用于滚动动态页面的函数,如何将文档作为参数传递?
I am designing a function in JS for scrolling dynamic page how can I pass document as an argument?
我正在设计一个JS函数来实现动态页面的滚动所以我在Scroll.feature中创建了一个函数as
@ignore
* def ScrollFunction()=
"""
function(document){
var height = document.body.scrollHeight
while(true){
window.scrollTo(0, document.body.scrollHeight)
var newHeight = document.body.scrollHeight
if (newHeight === height) {
break;
}
height = newHeight ;
}
}
"""
我将从另一个功能文件调用此函数进行滚动,但如何将文档参数传递给此函数?
抱歉,您需要花一些时间阅读和理解:https://github.com/intuit/karate/tree/master/karate-core#karate-vs-the-browser
即使您对空手道功能的理解也需要清楚:https://github.com/intuit/karate#multiple-functions-in-one-file
现在,只要 driver
已初始化,document
应该总是 工作。
一个提示是你可以像这样分解成多个部分:
* def getHeight = function(){ return script("document.body.scrollHeight") }
然后你可以在其他一些函数中使用getHeight()
。另请参阅 https://github.com/intuit/karate/tree/master/karate-core#function-composition
所以请在您再次尝试后打开一个新问题。
我正在设计一个JS函数来实现动态页面的滚动所以我在Scroll.feature中创建了一个函数as
@ignore
* def ScrollFunction()=
"""
function(document){
var height = document.body.scrollHeight
while(true){
window.scrollTo(0, document.body.scrollHeight)
var newHeight = document.body.scrollHeight
if (newHeight === height) {
break;
}
height = newHeight ;
}
}
"""
我将从另一个功能文件调用此函数进行滚动,但如何将文档参数传递给此函数?
抱歉,您需要花一些时间阅读和理解:https://github.com/intuit/karate/tree/master/karate-core#karate-vs-the-browser
即使您对空手道功能的理解也需要清楚:https://github.com/intuit/karate#multiple-functions-in-one-file
现在,只要 driver
已初始化,document
应该总是 工作。
一个提示是你可以像这样分解成多个部分:
* def getHeight = function(){ return script("document.body.scrollHeight") }
然后你可以在其他一些函数中使用getHeight()
。另请参阅 https://github.com/intuit/karate/tree/master/karate-core#function-composition
所以请在您再次尝试后打开一个新问题。