- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 CasperJS 阅读某个网页。我想要做的是在 CasperJS 中加载一个网页。然后,等待某个 HTML 元素具有特定文本。
所以我想做的是:
var casper = require('casper').create();
casper.start('http://www.example.com/somepage', function() {
this.echo('Home page opened');
});
// wait for text based on a CSS selector
casper.waitForText('.someCssClass', 'dolor sit', function() {
this.echo('found title!');
});
// when text is eventually found, then continue with this
casper.then(function() { ... } );
casper.run();
所以我想使用 waitForText
,但要使用 CSS
选择器。这样它就可以监视某个 HTML 元素中的一段文本。这是否可能以及如何可能对我来说并不是很明显。
这可以在 CasperJS 中完成吗?如果可以,我该怎么做?
最佳答案
以下函数从 waitForText()
function 中提取了一些逻辑并将其与 waitForSelector()
配对:
var utils = require("utils");
casper.waitForSelectorText = function(selector, text, then, onTimeout, timeout){
this.waitForSelector(selector, function _then(){
this.waitFor(function _check(){
var content = this.fetchText(selector);
if (utils.isRegExp(text)) {
return text.test(content);
}
return content.indexOf(text) !== -1;
}, then, onTimeout, timeout);
}, onTimeout, timeout);
return this;
};
将此代码放在脚本开头的某个位置,并像使用任何其他 CasperJS 函数一样使用该函数。 text
可以是字符串或正则表达式,选择器也可以是 XPath 表达式(使用辅助函数)。
关于javascript - 使用 CasperJS 等待元素具有特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32104784/
运行测试时获取。 FAIL 35 tests executed in 16.806s, 35 passed, 0 failed, 2 dubious, 0 skipped. “可疑”意味着什么?如何查
是否有人已经使用 casperjs 实现了著名的“页面对象模式”,从长远来看,它对于测试的可维护性非常有用? 当您必须将测试的机制和目的分开时,使用它非常非常酷。以这种方式编写测试会变得更加愉快。 有
所以,我试图在我的服务器上运行 casperJS 作为 cron 作业,这是 crontab: * * * * * /usr/local/bin/casperjs /var/www/javascrip
我知道如何禁用图像和插件,但似乎没有明显的选项来禁用 CasperJS 中的 css。 有谁知道这是如何工作的? 最佳答案 假设您想抑制所有外部样式表的加载,您可以通过中止加载 css 文件的请求来实
我在删除网站时从创建的 URL 下载文件时遇到问题。目前我发现了一个文件的月份和年份,然后替换了 url 中的值并尝试从该位置下载。我了解到您无法使用评估范围内的下载功能。 this.evaluate
在 CasperJS 中,如何在使用 casper.thenOpen() 时保持 session 例如: var casper = require('casper').create(); casper
我希望我的 casper 在 session 期间登录并保持登录状态。有可能吗?如果是这样,如何? 最佳答案 如果你想在 CasperJS 中存储 cookie,你可以使用 PhantomJS coo
我用 casperjs 编写了一些测试。他们与 phantomjs 一起运行得很好。但是,当我尝试通过以下命令使用 slimerjs 时: casperjs --verbose --engine=sl
我用 casperjs 编写了一些测试。他们与 phantomjs 一起运行得很好。但是,当我尝试通过以下命令使用 slimerjs 时: casperjs --verbose --engine=sl
我想单击“提交”按钮,等待下一页加载,然后在第二页上获取html。。我先做然后再运行,但然后一步仍在首页上运行。有任何想法吗? var casper = require('casper').creat
在我的页面自动化脚本中,当我单击标签链接时,将打开一个新窗口。链接的 url 是由复杂的 javascript 生成的。 办理任务 触发后 url 变为: https://oa.phicomm.co
CasperJS(带有 phantomJS)可以直接在浏览器中运行而不是通过命令行运行吗? 我想从浏览器运行交互式测试,我从用户那里获取输入并相应地进行。我想将 casperJS 作为在浏览器中执行的
我正在尝试使用 CasperJS 将图像上传到网络表单。 我的表格看起来像这样: ... Campaign Banner
错误: casper.test property is only available using the `casperjs test` command 在我的整个代码库中搜索了“casper.tes
假设我有一组网址。我不想使用 thenOpen 函数。因为它等待每个以前的 url 被加载并且它减少了加载时间。 casper.each(hrefs,function(self,href){
我正在尝试导航到从脚本本身创建的 url。 此示例代码不像(我曾)预期的那样工作。不知道为什么:( var casper = require('casper').create({ viewpo
我有一个链接列表,我必须模拟这些链接才能使用CasperJS进行点击。他们都共享同一个类(class)。 但是,使用this.click('.click-me')仅单击第一个链接。 单击所有链接的正确
casper.then(function(){ phone_number = '7wqeqwe6'; phone_password = 'Teqweqweqw34'; }); casper.t
我如何告诉 casper 不要加载图像、css、js 视频等。所以我只对 DOM 元素感兴趣。 最佳答案 看看 CasperJS API . var casper = require('casper'
在Phantom中生成PDF时,我可以这样设置纸张大小: page.paperSize = { height: '8.5in', width: '11in', orientation: '
我是一名优秀的程序员,十分优秀!