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
我打算假設你沒有閱讀過關於如何調試的文章。 –