【发布时间】:2017-07-04 13:35:44
【问题描述】:
目标
在这里,我尝试在
Pubmed website。假设我正在搜索的术语是Hello。最后我期望的是在点击搜索按钮后登陆结果页面。
问题
提交代码在 chrome 浏览器的 javascript 控制台上完美运行。但它不适用于 casperjs。 current-url 似乎保持不变。我不知道问题出在哪里。
我的代码
// USAGE: casperjs test navigation_test.js
var config = {
url: 'https://www.ncbi.nlm.nih.gov/pubmed/',
};
config.form = {
"term": "Hello",
};
casper.test.begin('Testing navigation and forms', 2, function suite(test) {
test.comment('⌚ Loading ' + config.url + '...');
casper.start(config.url, function() {
// adjust the view port
this.viewport(1280, 1024);
});
// #1 method-2 (short)
casper.then(function() {
this.fill('form#EntrezForm', config.form, true);
})
// #2
casper.then(function() {
test.assertUrlMatch(/term/, 'New location is ' + this.getCurrentUrl());
});
casper.run(function () {
test.done();
});
});
额外代码
上述代码中的#1 method 很短。我还尝试了更长的版本,如下所示。但它也没有工作。
// #1 method-1 (long)
casper.then(function() {
this.evaluate(function() {
$('term').value = "Hello"
});
test.assertEvalEquals(function () {
return $('term').value;
}, "Hello", 'The search was filled out properly.');
this.click('button[id="search"][type="submit"][class="button_search nowrap"]');
// OR
// this.clickLabel('Search', 'button');
// OR
/*this.evaluate(function() {
$('search').click();
// OR
// document.getElementById('search').click();
});*/
});
【问题讨论】:
标签: javascript node.js phantomjs casperjs