如何将动态参数传入函数,而不是硬编码字符串
问题描述:
我们在尝试传递存储在var中的参数时遇到问题。 问题是,我们正在将动态获取的div ID存储在变量中,然后将其传递给.moveToObject函数。如何将动态参数传入函数,而不是硬编码字符串
But the function throws back error ;
Error: invalid selector: No selector specified
Wanted to know how we can pass arguments stored in variables into various functions.
For instance in the code below , we are retiring sectionId via execute , storing it in sectionId variable .
then using it later on in moveToObject.
all functions seems to work when we are giving arguments inside "" quotes, but in our case we cannot do this. Please help us out how we can achieve this.
it('drag and drop should work', function() {
var sectionId = "";
// load page, then call function()
return driver
.url('http://localhost:9000')
.pause(7000)
.click('#layoutWizardButton')
.click('#tableWizardBuild')
.pause(3000)
.execute(function() {
sectionId = window.document.getElementById('Section1');
}
.moveToObject('#ribbon-radio-tile')
.buttonDown()
.moveToObject(sectionId) -- -- > errors out here
.buttonUp()
.pause(2000)
.end()
});
答
尝试.moveToObject(sectionId.value)