Ejemplo n.º 1
0
        public async Task TestAsync(DemoCard demoCard)
        {
            await AssertFillAsync(demoCard);

            await submitButton.ClickAsync();

            await Task.Delay(500);

            var resultEl = await demoCard.Page.QuerySelectorAsync("div.el-message-box__wrapper > div > div.el-message-box__content > div.el-message-box__message > p");

            var result = await resultEl.EvaluateFunctionAsync <string>("x=>x.innerText");

            Assert.Equal($"名称:测试活动,区域:Bejing,区域2:Bejing,日期:{DateTime.Now.ToString("yyyy/M/1")} 0:00:00,即时配送:False,性质:Offline,特殊资源:场地,枚举资源:Option1,活动形式:测试活动", result);
            var okButton = await demoCard.Page.QuerySelectorAsync("div.el-message-box__wrapper > div > div.el-message-box__btns > button");

            Assert.NotNull(okButton);
            await okButton.ClickAsync();

            await Task.Delay(500);

            okButton = await demoCard.Page.QuerySelectorAsync("div.el-message-box__wrapper > div > div.el-message-box__btns > button");

            Assert.Null(okButton);

            await resetButton.ClickAsync();

            await Task.Delay(50);

            await AssertFormAsync(demoCard, false, new List <int>());
        }
Ejemplo n.º 2
0
        public async Task IngresarEmpresa()
        {
            //Se selecciona la empresa ### document.querySelector("#contenido > form > table > tbody > tr:nth-child(4) > td > input.btn_empresa.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-state-hover")
            try
            {
                await Page.WaitForTimeoutAsync(4000);

                //await Page.WaitForExpressionAsync($"document.getElementById('{id_input_Umsatz}')!=null") #contenido > form > table > tbody > tr:nth-child(4) > td > input.btn_empresa
                //#contenido > form > table > tbody > tr:nth-child(4) > td > input.btn_empresa.ui-button.ui-widget.ui-state-default.ui-corner-all

                ElementHandle btnEmpresa = await NewPage.QuerySelectorAsync("#contenido > form > table > tbody > tr:nth-child(4) > td > input.btn_empresa.ui-button.ui-widget.ui-state-default.ui-corner-all");

                if (btnEmpresa != null)
                {
                    await btnEmpresa.ClickAsync();
                }
                else
                {
                    await Page.WaitForTimeoutAsync(4000);

                    ElementHandle btnEmpresa2 = await NewPage.QuerySelectorAsync("#contenido > form > table > tbody > tr:nth-child(4) > td > input.btn_empresa");

                    await btnEmpresa2.ClickAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Ejemplo n.º 3
0
        private async Task DiscoverServiceDesktop(Page page)
        {
            await page.GoToAsync(BaseUrl, DefaultNavigationOptions);

            ElementHandle allProductsButton = await page.WaitForSelectorAsync("a.login_all_products_button", DefaultWaitForSelectorOptions);

            if (allProductsButton != null)
            {
                await allProductsButton.ClickAsync(DefaultClickOptions);

                ElementHandle topMenuElements = await page.WaitForSelectorAsync("ul.ui_tabs.clear_fix", DefaultWaitForSelectorOptions);

                if (topMenuElements != null)
                {
                    DiscoveringCompleted.Set();
                }
            }
        }
Ejemplo n.º 4
0
        private async Task DiscoverServiceMobile(Page page)
        {
            await page.GoToAsync(BaseUrl, DefaultNavigationOptions);

            ElementHandle forgetPasswordButton = await page.WaitForSelectorAsync("div.near_btn.wide_button.login_restore", DefaultWaitForSelectorOptions);

            if (forgetPasswordButton != null)
            {
                await forgetPasswordButton.ClickAsync(DefaultClickOptions);

                ElementHandle restoreElements = await page.WaitForSelectorAsync("div.PanelHeader__container", DefaultWaitForSelectorOptions);

                if (restoreElements != null)
                {
                    DiscoveringCompleted.Set();
                }
            }
        }
Ejemplo n.º 5
0
        //funcion que llega a la pagina de comprobantes en linea de AFIP
        public async Task IrAComprobantesEnLinea()
        {
            await Page.WaitForTimeoutAsync(5000);

            //Se selecciona el boton de comprobantes en linea
            //await Page.WaitForSelectorAsync("document.querySelector("#servicesContainer > div:nth-child(8) > div > div > div > div.media-body > h4")
            try
            {
                await Page.WaitForSelectorAsync("#servicesContainer > div:nth-child(8) > div > div > div > div.media-body > h4");

                ElementHandle btnComprantes = await Page.QuerySelectorAsync("#servicesContainer > div:nth-child(8) > div > div > div > div.media-body > h4");

                if (btnComprantes != null)
                {
                    await btnComprantes.ClickAsync();

                    //Este evento detecta la pestaña de comprobantes en linea que se abre al hacer click

                    Browser.TargetCreated += async(sender, e) =>
                    {
                        if (e.Target.Url.Substring(0, URLComprobantes.Length).Equals(URLComprobantes))
                        {
                            NewPage = await e.Target.PageAsync();
                        }
                    };
                }
                else
                {
                    throw new Exception("No se detecta el boton de comprobantes en linea");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Ejemplo n.º 6
0
        public async Task ProcessAsync(MessageContext context, HttpApiClient api)
        {
            var uid = await EnsureGetBindingIdAsync(context.UserId).ConfigureAwait(false);

            var apiTask = OsuApi.GetUserInfoAsync(uid, Bleatingsheep.Osu.Mode.Standard).ConfigureAwait(false);

            using (var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false))
            {
                await page.SetViewportAsync(new ViewPortOptions
                {
                    DeviceScaleFactor = 2.75,
                    Width             = 1440,
                    Height            = 900,
                }).ConfigureAwait(false);

                await page.GoToAsync($"https://osu.ppy.sh/users/{uid}/osu").ConfigureAwait(false);

                // wait for load complete
                const string waitSelector = @"body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2)";
                await page.WaitForSelectorAsync(waitSelector).ConfigureAwait(false);

                const string bestSelector = "body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.play-detail-list";
                //ElementHandle bpsElement = await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false);

                const string  buttonSelector = "body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.profile-extra-entries__item > button";
                ElementHandle button         = await page.QuerySelectorAsync(buttonSelector).ConfigureAwait(false);

                ElementHandle[]? bpList = default;
                int maxTryTimes = 4;
                while (button != null && maxTryTimes-- != 0)
                {
                    //check bp counts.

                    bpList = await page.QuerySelectorAllAsync(bestSelector + " > div").ConfigureAwait(false);

                    await button.ClickAsync().ConfigureAwait(false);

                    // wait for click complete
                    await page.WaitForSelectorAsync(bestSelector + $" > div:nth-child({bpList.Length})",
                                                    new WaitForSelectorOptions { Timeout = 8000 /*ms*/ }).ConfigureAwait(false);

                    // seems that bp div adding and button availability changing is NOT synchronized
                    // wait for button availability change
                    await page.WaitForTimeoutAsync(500).ConfigureAwait(false);

                    // requery button
                    button = await page.QuerySelectorAsync(buttonSelector).ConfigureAwait(false);
                }

                if (bpList == null)
                {
                    await api.SendMessageAsync(context.Endpoint, "查询失败。").ConfigureAwait(false);

                    return;
                }

                // filter

                /*
                 * bpList = document.querySelectorAll("body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.play-detail-list > div");
                 *
                 * bpList.forEach((element) => { var dateTime = element.querySelector("div.play-detail__group.play-detail__group--top > div.play-detail__detail > div > span.play-detail__time > time").getAttribute("datetime"); if (new Date() - Date.parse(dateTime) > 86400000) element.remove();  })
                 */

                await page.EvaluateExpressionAsync(@"bpList = document.querySelectorAll(""body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.play-detail-list > div"");").ConfigureAwait(false);

                await page.EvaluateExpressionAsync(@"bpList.forEach((element) => { var dateTime = element.querySelector(""div.play-detail__group.play-detail__group--top > div.play-detail__detail > div > span.play-detail__time > time"").getAttribute(""datetime""); if (new Date() - Date.parse(dateTime) > 86400000) element.remove();  })").ConfigureAwait(false);

                // check
                bpList = await page.QuerySelectorAllAsync(bestSelector + " > div").ConfigureAwait(false);

                if (bpList.Length == 0)
                {
                    await api.SendMessageAsync(context.Endpoint, "最近 24 小时没有更新 bp。").ConfigureAwait(false);

                    return;
                }

                //screenshot
                //delete pinned elements
                await(await page.QuerySelectorAsync("body > div.js-pinned-header.hidden-xs.no-print.nav2-header > div.nav2-header__body").ConfigureAwait(false)).EvaluateFunctionAsync(@"(element) => element.remove()").ConfigureAwait(false);
                await(await page.QuerySelectorAsync("body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.hidden-xs.page-extra-tabs.page-extra-tabs--profile-page.js-switchable-mode-page--scrollspy-offset").ConfigureAwait(false)).EvaluateFunctionAsync(@"(element) => element.remove()").ConfigureAwait(false);

                // add extra information
                await page.EvaluateExpressionAsync($@"document.querySelector(""{bestSelector}"").parentElement.parentElement.querySelector(""h3"").textContent += "" (用户名:"" + {JsonConvert.SerializeObject((await apiTask).Item2?.Name ?? "获取失败")} + "" 查询时间:"" + {JsonConvert.SerializeObject(DateTime.Now.ToString("yyyy-MM-dd H:mm)"))}").ConfigureAwait(false);

                //ElementHandle printElement = await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false);
                var printElement =
                    await(await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false))
                    .EvaluateFunctionHandleAsync("(element) => element.parentNode.parentNode").ConfigureAwait(false) as ElementHandle;
                printElement ??= await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false);

                var data = await printElement.ScreenshotDataAsync(new ScreenshotOptions()).ConfigureAwait(false);

                await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false);
            }
        }
Ejemplo n.º 7
0
        ModifyProfile(Profile profile, LoginInfo loginInfo)
        {
            var browser = await PuppeteerInstance.getInstance();

            using (var page = await browser.NewPageAsync())
            {
                try
                {
                    await TwitterPoster.twitterLoginAsync(loginInfo, page);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                    await page.GoToAsync(URL);
                }

                await Task.Delay(3000);

                var profileButtonHandle = await page.WaitForSelectorAsync(ProfileSelector);

                await profileButtonHandle.ClickAsync();

                await Task.Delay(3000);

                var modifyButtonHandle = await page.WaitForSelectorAsync(ModifyButtonSelector);

                await modifyButtonHandle.ClickAsync();

                await Task.Delay(3000);

                ElementHandle modifyPictureHandle = null;
                try
                {
                    modifyPictureHandle = await page.WaitForSelectorAsync(ModifyPictureSelector);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                    modifyPictureHandle = await page.WaitForSelectorAsync("#page-container > div.ProfileCanopy.ProfileCanopy--withNav.js-variableHeightTopBar.ProfileCanopy--large > div > div.ProfileCanopy-header.u-bgUserColor > div.AppContainer > div.ProfileCanopy-avatar > div.ProfileAvatarEditing > div.ProfileAvatarEditing-buttonContainer > button > div.ProfileAvatarEditing-addAvatarHelp");

                    await Task.Delay(3000);
                }
                var modifyTitleHandle = await page.WaitForSelectorAsync(ModifyTitleSelector);

                var modifyDescriptionHandle = await page.WaitForSelectorAsync(ModifyDescriptionSelector);

                var modifySiteHandle = await page.WaitForSelectorAsync(ModifySiteSelector);

                var saveButtonHandle = await page.WaitForSelectorAsync(SaveButtonSelector);

                await modifyPictureHandle.ClickAsync();

                byte[]       byteArrayIn = profile.picture;
                MemoryStream ms          = new MemoryStream(byteArrayIn, 0, byteArrayIn.Length);
                ms.Position = 0;
                var returnImage = Image.FromStream(ms, true);
                returnImage.Save("./ModifyTEMP.png");
                var uploadPictureHandle = await page.WaitForSelectorAsync(UploadPictureSelector);

                await uploadPictureHandle.UploadFileAsync("./ModifyTEMP.png");

                var button = await page.WaitForSelectorAsync
                                 ("#profile_image_upload_dialog-dialog > div.modal-content > div.modal-footer > button.EdgeButton.EdgeButton--primary.profile-image-save");

                await button.ClickAsync();

                await Task.Delay(3000);

                await modifyTitleHandle.FocusAsync();

                await page.Keyboard.DownAsync("Control");

                await page.Keyboard.PressAsync("A");

                await page.Keyboard.UpAsync("Control");

                await page.Keyboard.PressAsync("Backspace");

                await page.Keyboard.TypeAsync(profile.title);

                await modifyDescriptionHandle.FocusAsync();

                await page.Keyboard.DownAsync("Control");

                await page.Keyboard.PressAsync("A");

                await page.Keyboard.UpAsync("Control");

                await page.Keyboard.PressAsync("Backspace");

                await page.Keyboard.TypeAsync(profile.description);

                await modifySiteHandle.FocusAsync();

                await page.Keyboard.DownAsync("Control");

                await page.Keyboard.PressAsync("A");

                await page.Keyboard.UpAsync("Control");

                await page.Keyboard.PressAsync("Backspace");

                await page.Keyboard.TypeAsync(profile.site);

                await saveButtonHandle.ClickAsync();

                await browser.CloseAsync();

                browser.Dispose();
            }
        }
Ejemplo n.º 8
0
        public async Task TestAsync(DemoCard card)
        {
            var tabs = new List <string>();

            tabs.Add("选项卡1");
            tabs.Add("卡2");
            tabs.Add("卡3");
            tabs.Add("Component");
            var originTabs = tabs.ToList();
            await Task.Delay(200);

            var headers = await GetHeadersAsync(card);

            await headers[0].Header.ClickAsync();
            await Task.Delay(200);

            ElementHandle closeIcon = null;

            while (true)
            {
                var headerItem = headers.FirstOrDefault();
                if (headerItem.Header == null)
                {
                    break;
                }
                await headerItem.Header.ClickAsync();

                await Task.Delay(200);

                closeIcon = await headerItem.Header.QuerySelectorAsync("span.el-icon-close");

                Assert.NotNull(closeIcon);
                await closeIcon.ClickAsync();

                await Task.Delay(200);

                tabs.RemoveAt(0);
                headers = await GetHeadersAsync(card);
            }
            await AssertEmptyBody(card);

            var newTab = await card.Body.QuerySelectorAsync("button");

            tabs.Add("标题0");
            tabs.Add("标题1");
            tabs.Add("标题2");
            tabs.Add("标题3");
            for (int i = 0; i < 4; i++)
            {
                await newTab.ClickAsync();

                await Task.Delay(200);
            }
            headers = await GetHeadersAsync(card);

            while (true)
            {
                var headerItem = headers.LastOrDefault();
                if (headerItem.Header == null)
                {
                    break;
                }
                await headerItem.Header.ClickAsync();

                await Task.Delay(200);

                closeIcon = await headerItem.Header.QuerySelectorAsync("span.el-icon-close");

                Assert.NotNull(closeIcon);
                await closeIcon.ClickAsync();

                await Task.Delay(200);

                tabs.RemoveAt(tabs.Count - 1);
                headers = await AssertTabAsync(card, tabs, tabs.Count - 1);
            }
            await AssertEmptyBody(card);

            var count = 5;
            await newTab.ClickAsync();

            await Task.Delay(200);

            while (count-- > 0)
            {
                await newTab.ClickAsync();

                await Task.Delay(200);

                headers = await GetHeadersAsync(card);

                Assert.Equal(2, headers.Count);
                tabs = headers.Select(x => x.Title).ToList();
                var   tabHeaders = headers.Select(x => x.Header).ToArray();
                await headers[0].Header.ClickAsync();
                await Task.Delay(200);
                await AssertHeaderAsync(tabHeaders, 0);

                closeIcon = await headers[0].Header.QuerySelectorAsync("span.el-icon-close");
                await closeIcon.ClickAsync();

                tabs.RemoveAt(0);
                await Task.Delay(200);

                headers = await GetHeadersAsync(card);

                Assert.Single(headers);
                var body = await card.Body.QuerySelectorAsync("div.el-tabs.el-tabs--card.el-tabs--top > div.el-tabs__content");
                await AssertBodyAsync(body, headers[0].Title);
            }
        }
Ejemplo n.º 9
0
        public async Task <List <VkBrwCommunity> > GetCommunities(BrowserContext userContext, Page userPage, VkBrwUser user)
        {
            List <VkBrwCommunity> nwPages = new List <VkBrwCommunity>();

            await userPage.GoToAsync(user.ProfileLink);

            ElementHandle userIsLoaded = await userPage.WaitForSelectorAsync("#page_info_wrap.page_info_wrap");

            ElementHandle[] hiddenProfileBlock = await userPage.QuerySelectorAllAsync("h5.profile_deleted_text");

            if (hiddenProfileBlock.Length == 0)
            {
                ElementHandle idolsLoaded = await userPage.WaitForSelectorAsync("#profile_idols");

                // Интересные страницы
                ElementHandle[] noteworthyPagesBlock = await userPage.QuerySelectorAllAsync("#profile_idols.module.clear.page_list_module._module");

                if (noteworthyPagesBlock.Length == 1)
                {
                    ElementHandle   noteworthyPages            = noteworthyPagesBlock.First();
                    ElementHandle[] noteworthyPagesHeaderBlock = await noteworthyPages.QuerySelectorAllAsync("a.module_header");

                    if (noteworthyPagesHeaderBlock.Length == 1)
                    {
                        ClickOptions clickOptions = new ClickOptions {
                            Delay = new Random().Next(30, 100)
                        };

                        ElementHandle noteworthyPagesLinkElement = noteworthyPagesHeaderBlock.First();
                        await noteworthyPagesLinkElement.ClickAsync(clickOptions);

                        ElementHandle noteworthyPagesIsOpened = await userPage.WaitForSelectorAsync("#fans_rowsidols.fans_rows.fans_idols");

                        ElementHandle[] closeBlock = await userPage.QuerySelectorAllAsync("div.box_x_button");

                        if (closeBlock.Length == 1)
                        {
                            ElementHandle[] pagesCountBlock = await userPage.QuerySelectorAllAsync("span.ui_box_header_cnt");

                            if (pagesCountBlock.Length == 1)
                            {
                                ElementHandle pagesTotalCountElement = pagesCountBlock.First();
                                string        pagesTotalCountValue   = await pagesTotalCountElement.EvaluateFunctionAsync <string>("('span', span => span.innerText)");

                                if (!string.IsNullOrEmpty(pagesTotalCountValue))
                                {
                                    bool pagesTotalCountReceived = int.TryParse(pagesTotalCountValue, out int pagesTotalCount);

                                    if (pagesTotalCountReceived && pagesTotalCount > 0)
                                    {
                                        ElementHandle[] pagesVisibleElements = await userPage.QuerySelectorAllAsync("div.fans_idol_row.inl_bl");

                                        if (pagesVisibleElements.Length < pagesTotalCount)
                                        {
                                            PressOptions pressOptions = new PressOptions {
                                                Delay = new Random().Next(20, 40)
                                            };

                                            await userPage.FocusAsync("input");

                                            await userPage.Keyboard.PressAsync("Tab", pressOptions);

                                            int visiblePagesCounter = pagesVisibleElements.Length;

                                            while (visiblePagesCounter < pagesTotalCount)
                                            {
                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                ElementHandle[] newPagesVisibleElements = await userPage.QuerySelectorAllAsync("div.fans_idol_row.inl_bl");

                                                if (newPagesVisibleElements.Length == visiblePagesCounter)
                                                {
                                                    break;
                                                }

                                                visiblePagesCounter = newPagesVisibleElements.Length;
                                            }
                                        }

                                        ElementHandle[] nwPagesElements = await userPage.QuerySelectorAllAsync("div.fans_idol_info");

                                        foreach (var element in nwPagesElements)
                                        {
                                            VkBrwCommunity community = await GetCommunityAsync(element, userContext);

                                            if (community != null)
                                            {
                                                nwPages.Add(community);
                                                community.Users.Add(user);
                                            }
                                        }
                                    }
                                }
                            }

                            ElementHandle closeButtonElement = closeBlock.First();
                            await closeButtonElement.ClickAsync(clickOptions);
                        }
                    }
                }
            }
            else
            {
                user.HiddenProfile = true;

                ElementHandle[] pageNameElements = await userPage.QuerySelectorAllAsync("h2.page_name");

                if (pageNameElements.Length == 1)
                {
                    var pageElement = pageNameElements.First();
                    user.PageName = await pageElement.EvaluateFunctionAsync <string>("('h2', h2 => h2.innerText)");
                }
            }

            return(nwPages);
        }