前提・実現したいこと
nodejsにてnightmareというライブラリを用いて、ヨドバシドットコムで自動注文をすることまでは成功。条件分岐(ifelse)を付けると後者が止まってしまう。前者はうまくいく。この分岐を付ける理由は、注文時にクレカ番号を再入力する画面が出る場合があり、その場合条件分岐をしないと止まってしまうので。
発生している問題・エラーメッセージ
エラーメッセージは特にない。実行中に止まってしまう。
該当のソースコード
java
1var Nightmare = require('nightmare'); 2var nightmare = Nightmare({ show: true }); 3var mail = '●'; 4var password = '●'; 5var securityCode = '●'; // !!! DANGER !! 6var itemUrl = 'https://www.yodobashi.com/product/100000001001264539/index.html'; 7 8// 前提条件:ログインしていない 9nightmare 10 .goto(itemUrl) 11 .wait('#js_buyBox') 12 // 商品をカートに追加 13 .select('select#qtySel','1' ) 14 .click('.yBtnText') 15 // 購入手続きへ進む 16 .wait('.cartinBox') 17 .goto('https://order.yodobashi.com/yc/shoppingcart/index.html?next=true') 18 .click('#sc_i_buy') 19 // ログイン 20 .wait('#js_i_form') 21 .type('input#memberId', mail) 22 .type('input#password', password) 23 .click('#js_i_login0') 24 // ログインするとカートへリダイレクトされるので表示されるまで待つ 25 .wait('.cartItemBlock') 26 .click('#sc_i_buy') 27 //メインフローの分岐 28 .wait('10000ms') 29 .exists('input#cardNumber') 30 .then(function (result) {if (result) { 31return nightmare.type('input#cardNumber','●') 32.select('select#cardExpirationMonth','●') 33.select('select#cardExpirationYear','●') 34.click('#js_i_next.btnRed') 35.wait('.dashboardElement') 36.click('.btnOrange.js_c_payment.js_c_filterBtn') 37.wait('.gpSelectUnit.slctInputUnit') 38.click('.js_c_point_select.js_c_usePoint') 39.type('input#goldPointForUse', '●') 40.click('.btnRed.js_c_next') 41.wait('#creditCard\.securityCode') 42.insert('#creditCard\.securityCode', securityCode) 43.click('.btnRed.js_c_order.js_c_filterBtn') 44.end() 45.then((result) => {console.log('done');}) 46.catch((error) => {console.error('Search failed:', error);}) 47} else { 48nightmare 49.wait('.dashboardElement') 50.click('.btnOrange.js_c_payment.js_c_filterBtn') 51.wait('.gpSelectUnit.slctInputUnit') 52.click('.js_c_point_select.js_c_usePoint') 53.type('input#goldPointForUse', '●') 54.click('.btnRed.js_c_next') 55.wait('#creditCard\.securityCode') 56.insert('#creditCard\.securityCode', securityCode) 57.click('.btnRed.js_c_order.js_c_filterBtn') 58.end() 59.then((result) => {console.log('done');}) 60.catch((error) => {console.error('Search failed:', error);}) 61}});
試したこと
やりようがない。。。
補足情報(FW/ツールのバージョンなど)
winodows10

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/13 06:24