前提・実現したいこと
node.jsとpupetterでyoutubeで検索ボタンを押して画面をキャプチャーしています。
buttonを押すところでエラーになっています。
node.js、1日目なので、どう回避したものか困っています。
clickがnullとか言われていますがどういう意味でしょう?
ボタンを見つけられないのか、それともclickを間違えているのか。
回避策をいただければなおうれしいです。
//でコメントしたのはC#のコードと、try&errorのコードです。
発生している問題・エラーメッセージ
Desktop\puppeteer-master\node_modules\puppeteer\examples> node.exe .\youtube.js (node:2224) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'click' of null (node:2224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. PS C:\Users\username\Desktop\puppeteer-master\node_modules\puppeteer\examples> node.exe .\youtube.js (node:13860) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'click' of null (node:13860) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
該当のソースコード
js
1'use strict'; 2 3const puppeteer = require('puppeteer'); 4 5(async() => { 6 const browser = await puppeteer.launch(); 7 const page = await browser.newPage(); 8 9 //(1)Process.Start("http://www.youtube.com/"); 10 await page.goto('http://www.youtube.com/'); 11 12 //(2)HtmlElement searchbox = webBrowser.Document.GetElementById("search-input"); 13 //searchbox.InnerText="検索キーワード"; 14 //<div id="search-input" slot="search-input"><input name="search_query" tabindex="0" class="ytd-searchbox" id="search" role="combobox" aria-haspopup="false" autofocus="" style="outline: invert;" dir="ltr" spellcheck="false" aria-autocomplete="list" aria-label="検索" type="text" placeholder="検索" autocomplete="off" autocorrect="off" autocapitalize="none"></div> 15 await page.type('#search-input', 'Lemon'); 16 //(3)HtmlElement searchbutton = webBrowser.Document.GetElementById("search-icon-legacy"); 17 //searchbutton.InvokeMember("click"); 18 19 const searchbutton = await page.$('search-icon-legacy'); 20 await searchbutton.click(); 21 22 // const searchbutton = 'search-icon-legacy'; 23 // await page.click(searchbutton); 24 25 26 await page.screenshot({path: 'example2.png'}); 27 await browser.close(); 28})(); 29
補足情報(FW/ツールのバージョンなど)
Windows10 64bit
node.js v8.9.4
pupetter
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/22 02:56
2018/03/22 03:01