0
尽管.type()效果很好,但我不能让nightmareJS点击搜索按钮。 可能是什么问题?NightmareJS .click()方法 - 选择器问题
.type('form[action="/search/web/direct_search.php"] [class=_1frb]', string)
.click('form[action="/search/web/direct_search.php"] [type=submit]')
//.click('#js_x > form > button')
//.click('button[class="_42ft _4jy0 _4w98 _4jy3 _517h _51sy"]')
开发工具控制台找到按钮:
document.querySelector('form[action="/search/web/direct_search.php"] [type=submit]')
<button value="1" class="_42ft _4jy0 _4w98 _4jy3 _517h _51sy" aria-label="Search" tabindex="-1" data-testid="facebar_search_button" type="submit">…</button>
后来编辑:
你去那里,我的朋友,我已经去除了进口,把一切都在一个单一的文件,我已经用cookie登录,所以这是复制问题的完整代码:
var Nightmare = require('nightmare');
var nightmare = Nightmare({
show: true
});
var string = "TEST";
var search = function(string) {
return function(nightmare) {
nightmare
.goto('http://www.facebook.com')
.wait('form[action="/search/web/direct_search.php"] [class=_1frb]')
.type('form[action="/search/web/direct_search.php"] [class=_1frb]', string)
.click('form[action="/search/web/direct_search.php"] [type=submit]')
// .click('#js_x > form > button')
// .click('button[class="_42ft _4jy0 _4w98 _4jy3 _517h _51sy"]')
.wait(2000)
.screenshot('after.png')
.then(function() {
return nightmare
.wait();
})
};
};
nightmare
.useragent('...')
.use(search(string))
欢迎来到Stack Overflow!它看起来像你需要学习使用调试器。请帮助一些[互补调试技术](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果您之后仍然有问题,请随时返回更多详情。 –
@JoeC我相应地更新了我的帖子。 – Dobi
我打算假设你没有阅读过关于如何调试的文章。 –