木偶无法处理对话框

时间:2018-11-02 07:55:56

标签: node.js puppeteer

代码是this的副本,变化很小。

它模拟:

  • 只需转到Add to Chrome中的附加页面。

  • 在附加页面中,单击cancel按钮,然后会弹出一个窗口。单击const puppeteer = require('puppeteer') puppeteer.launch({headless: false}).then(async browser => { const page = await browser.newPage() await page.goto('https://chrome.google.com/webstore/detail/evernote-web-clipper/pioclpoplcdbaefihamjohnefbikjilc?utm_source=inline-install-disabled') page.on('dialog', async dialog => { console.log(dialog.message()) await dialog.dismiss() await browser.close() }) await page.waitForSelector('div[aria-label="Add to Chrome"]') await page.click('div[aria-label="Add to Chrome"]') await page.waitFor(20000) }) 按钮以关闭弹出窗口。

但是它不起作用。弹出窗口出现了,但是没有关闭。

puppeteer: 1.9.0
node: v10.6.0

有什么想法吗?

谢谢!

private static class DownloadFileTask extends AsyncTask<String, String, String> {
    String notiType = null;

    String dlink = null;
    String fileName = null;

    private WeakReference<MyFirebaseMessagingService> activityReference;


    DownloadFileTask(MyFirebaseMessagingService context) {
        activityReference = new WeakReference<>(context);
    }


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.d(TAG, "DownloadFile");
    }

    @Override
    protected String doInBackground(String... payload) {

        int count;
        String filePath = null;
        notiType = payload[0];
        dlink = payload[1];
        fileName = payload[2];

        try {
            URL url = new URL(dlink);
            URLConnection conection = url.openConnection();
            conection.connect();
            int lenghtOfFile = conection.getContentLength();
            InputStream input = new BufferedInputStream(url.openStream(), 8192);
            OutputStream output = null;

            switch (notiType) {
                case Notification_001:
                    filePath = activityReference.get().getFileDir("/DownloadedFiles", fileName);
                    break;

                case Notification_002:
                    filePath = activityReference.get().getFileDir("/DownloadedAPK", fileName);
                    break;

                   default:

                    break;
            }

            if (filePath != null) {
                File myFile = new File(filePath);
                if (myFile.exists()) {
                    myFile.delete();
                    Log.d(TAG, "file exist. delete it first");
                }
            }

            output = new FileOutputStream(filePath);
            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
                publishProgress("" + (int) ((total * 100) / lenghtOfFile));

                output.write(data, 0, count);
            }
            output.flush();
            output.close();
            input.close();

        } catch (Exception e) {
            Log.e(TAG, "exception", e);
        }

        return filePath;
    }

    protected void onProgressUpdate(String... progress) {
    }

    @Override
    protected void onPostExecute(String file_url) {
        if (file_url == null) {
            Log.d(TAG, "DownloadFile Error");
            activityReference.get().setToast("ERROR downloading file.. URL is invalid.");
        } else {
            Log.d(TAG, "DownloadFile Finish");
            File file = new File(file_url);
            if (file.exists() && file.length() > 0) {


                switch (notiType) {

                    case Notification_001:

                            if (activityReference.get().isAppInForeground) {


                            }           

                            Log.d(TAG, "Task finish");                         
                        break;
                    case Notification_002:
                       break;
                    default:
                        break;

                }

        } else{

            activityReference.get().setToast("File downloaded but file has 0 size.");
        }
    }
}

0 个答案:

没有答案