0

我正在使用casperJS导入文件,下面是对话框的HTML脚本和图片

文件上传对话框

<div class="container">
<p>Import notebooks from another GitHub instance.</p>
<p>Currently import does not preserve history.</p>
<p>
source repo api url: 
<input id="import-source" class="form-control-ext" type="text" value="https://api.github.com" style="width:100%;">
</p>
<p>
notebooks:
<br>
<textarea id="import-gists" class="form-control-ext" form="port" cols="30" rows="10" style="height: 20%;width: 50%;max-width: 100%"></textarea>
</p>
<p>
prefix (e.g.
<code>folder/</code>
to put notebooks in a folder): 
<input id="import-prefix" class="form-control-ext" type="text" style="width:100%;">
</p>
</div>

场景是我需要在笔记本字段中输入笔记本的 ID,然后单击导入。下面是我使用的 casperJS 代码

casper.then(function(){
    this.click({type:'xpath', path:".//*[@id='rcloud-navbar-menu']/li[3]/a"});
    if(this.test.assertVisible('#import_notebooks'),"Import external notebook is visible")
    {
        this.click('#import_notebooks');
    }else
    {
        console.log('Import external notebook is not visible');
    }
    this.wait(2000);
});

casper.then(function(){
    this.sendKeys({type:'css',path:"#import-gists"}, notebookID);
    this.click('.btn.btn-primary');
});

对话框打开但无法在笔记本字段中输入文本。

4

2 回答 2

1

回答我自己的问题很奇怪,但找到了解决方案。

casper.then(function () {
        this.evaluate(function() { $('#import_notebooks').click(); });
        this.echo('opened import notebooks dialog');
        this.wait(2000);
        this.evaluate(function() { $('#import-gists').val('importing Notebook ID'); });
        this.echo('inputted notebook name');
        this.wait(2000);
        this.evaluate(function() { $('#import-prefix').val('Prefix name/'); });
        this.echo('inputted prefix');
        this.wait(2000);
        this.evaluate(function() { $('#import-notebooks-dialog span.btn-primary').click(); });
    });
于 2015-05-27T04:37:25.723 回答
0

casper.test.assertVisible()不返回表示断言结果的布尔值。它返回一个结果对象。该行在语法上也不是正确的。

您可能想要使用的是casper.visible()

if(this.visible('#import_notebooks')) {
    this.click('#import_notebooks');
} else {
    console.log('Import external notebook is not visible');
}
于 2015-05-11T14:20:17.773 回答