0

当我单击按钮时,弹出页面正在打开。我必须点击它的按钮。我该怎么做?

await page.GoToAsync("https://.....");```
await page.WaitForTimeoutAsync(7000 * 2);```
await page.WaitForSelectorAsync("a[class='visit_button']");```
await page.ClickAsync("a[class='visit_button']"); //open popup``` 
await page.WaitForTimeoutAsync(3000);``` 
// I click to button on pop-up``` 
4

2 回答 2

0

这对我有用:

var alertMessage = "";
//attach to page during entire page life-cycle (until closed).
//handles the case where an javscript alert comes up during login.
page.Dialog += new EventHandler<DialogEventArgs>(async (sender, args) =>
{
    alertMessage = args.Dialog.Message;
    await args.Dialog.Accept(); //this closes it..
    Log.Information("Popup squashed in Login(): {0}", alertMessage);
    Thread.Sleep(500);
});
于 2020-03-31T13:57:08.093 回答
0

根据PageEventsPopupTests

await page.GoToAsync("https://.....");

await page.ClickAsync("a[class='visit_button']"); //Open Popup

var popupTaskSource = new TaskCompletionSource<Page>();
page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await popupTaskSource.Task;

var popupPage = popupTaskSource.Task.Result; // Popup Page

await popupPage.ClickAsync("a[class='btn']"); //Click on button in popup page

于 2021-10-12T11:31:52.203 回答