【发布时间】:2015-01-29 06:38:56
【问题描述】:
我正在尝试通过 casperjs 自动化 asp 编写的网站的几个步骤。我想获得关注。
- 导航到登录页面
- 填写用户名和密码字段
- 点击登录按钮
- 截取成功页面的截图
但到目前为止,我只能完成该过程的第一步。源视图页面对我来说看起来有点连线。大多数节点都以<ui:> 标记开头,我对此一无所知。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="theme/xslt/all.xsl?build=2.0.012&theme=theme_immi" ?>
<!DOCTYPE html [ <!ENTITY nbsp " "> ]>
<ui:root title="ImmiAccount - Login" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:ui="http://www.immi.gov.au/Namespace/UI/V1.0">
我第一次尝试fillSelectors()方法提交表单。
casper.start('https://online.immi.gov.au/lusc/login',function() {
this.echo(this.getTitle());
this.fillSelectors('#app_L2',{
'input[id="app_L2b0a0a0a3a1a"]': 'john',
'input[id="app_L2b0a0a0a3b1a"]': 'john123'
});
this.wait('2000',function(){
this.capture('formfill.png');
});
});
casper.then(function() {
// Click on 1st result link
this.click('#app_L2b0a0a0a4a');
this.wait('5000',function(){
this.capture('success.png');
})
});
出现以下错误
CasperError: Errors encountered while filling form: no field matching css selector "input[id="app_L2b0a0a0a3a1a"]" in form;
no field matching css selector "input[id="app_L2b0a0a0a3b1a"]" in form
然后尝试fillXPath()
casper.start('https://online.immi.gov.au/lusc/login',function() {
this.echo(this.getTitle());
this.fillXPath('#app_L2',{
'//*[@id="app_L2b0a0a0a3a1a"]': 'john',
'//*[@id="app_L2b0a0a0a3b1a"]': 'john123'
});
this.wait('2000',function(){
this.capture('formfill.png');
});
});
casper.then(function() {
// Click on 1st result link
this.click(x('//*[@id="app_L2b0a0a0a4a"]'),
this.wait('5000',function(){
this.capture('success.png');
}));
});
发生以下错误
CasperError: Errors encountered while filling form: Unable to find field element in form: FieldNotFound: Invalid field type; only HTMLElement and NodeList are supported; Unable to find field element in form: FieldNotFound: Invalid field type; only HTMLElement and NodeList are supported
最后,我尝试了sendkeys() 方法来填充字段,并尝试click() 来点击登录按钮。再次,没有找到成功。这是执行此操作的代码
this.sendKeys('#app_L2b0a0a0a3a1a', 'john');
this.sendKeys('#app_L2b0a0a0a3b1a', 'john123');
this.click(x('//*[@id="app_L2b0a0a0a4a"]'),
this.wait('5000',function(){
this.capture('ctrlqpass.png');
})
);
上面的代码既不会触发错误也不会触发成功页面。在所有情况下,casper 都会捕获初始页面的屏幕截图。非常感谢任何帮助..谢谢
【问题讨论】:
标签: javascript asp.net xpath phantomjs casperjs