mad*_*low 4 javascript casperjs
我想在运行一些CasperJs浏览器测试之前运行一些设置例程.
有一次我无法填写表格数据,因为有一些错位的HTML(表格标签放在表格中):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<table>
<form id="test1">
<input type="text" name="selector_1" />
</form>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是一个简单的测试用例:
casper.test.begin('Test', 0, function suite(test) {
casper.start('http://localhost:8000', function() {
this.fill('form#test1', {
"selector_1": 'Yo!'
}, true);
});
casper.run(function() {
test.done();
});
});
Run Code Online (Sandbox Code Playgroud)
测试结果是: error: Errors encountered while filling form: no field matching names selector "selector_1" in form
当我在这个例子中删除表标记时,它可以工作.
不幸的是,我不能在"现实世界"中改变这一点,因为破坏的HTML来自我没有源代码访问的应用程序.
这可以直接用CasperJs解决吗?
我想我也可以尝试通过替换损坏的部分来"修复"HTML.这可能是让这个工作的唯一方法吗?
您应该尝试使用fillXPath(但它在1.1版中可用):
casper.test.begin('Test', 0, function suite(test) {
casper.start('http://127.0.0.1:8020/test_casper/testme.html', function() {
this.test.assertExists({
type: 'xpath',
path: '//*[@name="selector_1"]'
}, 'the element exists');
this.fillXPath('form#test1', {
'//input[@name="selector_1"]': 'Yo!'
}, true);
});
casper.run(function() {
test.done();
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
310 次 |
| 最近记录: |