CasperJS:如何填写 asp 表格
CasperJS: How to fill a asp form
我正在尝试通过 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 捕获初始页面的屏幕截图。非常感谢任何帮助..谢谢
该页面是一个 XML 文档,带有用于将页面转换为 HTML 或 XHTML 的附加样式表 (XSL)。大多数浏览器会自动完成此操作。
PhantomJS 似乎默认编译时禁用了 XSLT 处理。因此,样式表未被处理,PhantomJS 将其视为任意数据。
您可以使用所需的选项集编译 PhantomJS 或使用 SlimerJS 作为 CasperJS 的引擎。使用的gecko引擎默认支持XSLT转换
另一种方法可能是使用 JavaScript 中包含的 XSLTProcessor 自己转换内容,但这在 PhantomJS 中也不可用。
我正在尝试通过 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 捕获初始页面的屏幕截图。非常感谢任何帮助..谢谢
该页面是一个 XML 文档,带有用于将页面转换为 HTML 或 XHTML 的附加样式表 (XSL)。大多数浏览器会自动完成此操作。
PhantomJS 似乎默认编译时禁用了 XSLT 处理。因此,样式表未被处理,PhantomJS 将其视为任意数据。
您可以使用所需的选项集编译 PhantomJS 或使用 SlimerJS 作为 CasperJS 的引擎。使用的gecko引擎默认支持XSLT转换
另一种方法可能是使用 JavaScript 中包含的 XSLTProcessor 自己转换内容,但这在 PhantomJS 中也不可用。