microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

The click effect is inconsistent in the iframe of Chromium and Firefox? #1269

Closed weizhuangzhi closed 3 years ago

weizhuangzhi commented 3 years ago

Use playwright to test the iframe, and if the browser uses Chromium, everything works normally. But when trying to use Firefox, click a link or button in the iframe, and then get the page title. The program does not wait for the end of the page navigation to get the page title immediately, resulting in inconsistent results between the program execution in Chromium and Firefox. How do I use the same code? And to ensure the consistent results of the implementation.

Below is a simple example of simulation

    using PlaywrightSharp;
    using System;
    using System.Threading.Tasks;

    namespace AutomationTesting
    {
        class Program
        {
            static async Task Main(string[] args)
            {
                using var playwright = await Playwright.CreateAsync();

                await using var browserChromium = await playwright.Chromium.LaunchAsync();
                await ShowTitle(browserChromium);

                await using var browserFirefox = await playwright.Firefox.LaunchAsync();
                await ShowTitle(browserFirefox);

            }

            private static async Task ShowTitle(IBrowser browser)
            {
                var page = await browser.NewPageAsync();
                await page.GoToAsync("https://iframetester.com/?url=https://www.bing.com");
                await page.Frames[1].ClickAsync("#scpl0");
                Console.WriteLine(await page.Frames[1].GetTitleAsync());
            }
        }
    }

PlaywrightSharp Version="0.191.2"

pavelfeldman commented 3 years ago

Browsers are different, so they react on clicks differently. You should probably wait for navigation explicitly if that is your goal: see https://playwright.dev/dotnet/docs/navigations#asynchronous-navigation.