How to change PageLoadStrategy for Selenium?

  • Created

We recommend that you read the Getting started with Kameleo Automation article before reading this one.

Once you use Selenium to automate Kameleo's browser for web scraping that will help you to bypass anti-bot solutions, you can change the page load strategy. In the case of using Kameleo with Selenium, the browser is already running by the time you want to connect to it with a WebDriver, and the WebDriver is launched by Kameleo.CLI instead of your Selenium package. For this, some additional options must be passed to Kameleo.CLI if you want to change the web driver's behavior.

You need to start the browser with POST /profiles/{guid}/start endpoint and pass additionalOptions to it. See the documentation on SwaggerHub. Currently, there are the supported keys: 'disableTouchEmulation' and 'pageLoadStrategy'

This way you can change pageLoadStrategy by defining in the additionalOptions

  • await client.startProfileWithOptions(profile.id, {
      body: {
        additionalOptions: [
          {
            key: 'pageLoadStrategy',
            value: 'eager',
          },
        ],
      },
    });

    See full example here.

  • await client.StartProfileWithOptionsAsync(profile.Id, new WebDriverSettings
    {
      AdditionalOptions = new List<Preference>
      {
        new Preference("pageLoadStrategy", "eager"),
      }
    });

    See full example here.

  • client.start_profile_with_options(profile.id, WebDriverSettings(
      additional_options=[
        Preference(key="pageLoadStrategy", value="eager")
      ]
    ))

    See full example here.

If you need to pass some other keys, please contact us.

Was this article helpful?

1 out of 1 found this helpful