nima ansari
nima ansari

Reputation: 582

How to not wait for page load in ChromeDriver in C#?

I'm trying to read some values from a bunch of URLs. These values exist on the page when the page is not fully loaded. However, ChromeDriver waits for the page to fully load. I searched and found out that DesiredCapabilities can be used to set the IWebDriver to not wait for full page load.

However, I can't find that class in C#, and the examples are written for python and other IWebDrivers, like IE and Firefox.

How can I instruct ChromeDriver not to wait for full page load in C#?

As I mentioned in my question, I've already seen those questions. I have two problems though:

  1. They are not for C#, and in C# I can't find DesiredCapabilities class, thus I can't pass that parameter. All I find is ReadOnlyDesiredCapabilities class, and one ICapabilities interface. And I don't know how to use them.

  2. They are not written for ChromeDriver and C#. They are for Java, Python, and other IWebDrivers. So, those Q&A don't help me.

Upvotes: 0

Views: 753

Answers (1)

Mohsen Hosseinalizadeh
Mohsen Hosseinalizadeh

Reputation: 315

Use this:

var option = new ChromeOptions();

//PageLoadStrategy.None => Does not wait for pages to load, returning immediately.
//PageLoadStrategy.Eager => Waits for pages to load and for ready state to be 'interactive' or 'complete'.
//PageLoadStrategy.Normal => Waits for pages to load and ready state to be 'complete'.
//PageLoadStrategy.Default => Indicates the behavior is not set.

option.PageLoadStrategy = PageLoadStrategy.None;
IWebDriver Driver = new ChromeDriver(option);

Upvotes: 1

Related Questions