Cloudfare prevent selenium bot

Hello everyone, I am an Automation Tester that worked for a project. From last week, my automated test scripts starts to fail and I discovered that the reason is this project switch using cloudfare.

I do some research and know that cloudfare has a mechanism to prevent automation bot.
The POC of cloudfare dashboard sent me a user_agent and I setup it in my Selenium code but it still fails randomly. He showed me that all request from this user_agent is marked as BYPASS and he also add my public IP address to AllowList but my Selenium testcases still fails randomly. Sometimes it runs, sometime it stuck and return with below error:

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:55379/session/e8537ad189d3255b4687c80916278934/url timed out after 60 seconds.
  ----> System.Threading.Tasks.TaskCanceledException : The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.
  ----> System.TimeoutException : The operation was canceled.
  ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
  ----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
  ----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:55379/session/e8537ad189d3255b4687c80916278934/cookie timed out after 60 seconds.
  ----> System.Threading.Tasks.TaskCanceledException : The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.
  ----> System.TimeoutException : The operation was canceled.
  ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
  ----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
  ----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.

  Stack Trace: 
HttpCommandExecutor.Execute(Command commandToExecute)
DriverServiceCommandExecutor.Execute(Command commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.set_Url(String value)
Navigator.GoToUrl(String url)
BasePage.RedirectToPage(IWebDriver driver, String url) line 102
CommonPage.NavigateToSpecificPageByUrl(IWebDriver driver, String url) line 57
Regression_Test_10_Videos_Are_Loaded.TC_01_Ensure_Videos_Are_Loaded(String videoPath) line 46
--TaskCanceledException
HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
<29 more frames...>
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
--IOException
AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
Int32>.GetResult(Int16 token)
HttpConnection.InitialFillAsync(Boolean async)
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--SocketException

The most difficulty is I do not have right to interact with Cloudfare dashboard so it makes the debug is is very challenge. I only receive the timeout exception in console (timeout because Selenium request is blocked by Cloudfare so it waits until driver wait is timeout).
Does anyone here face this problem before. I really appreciate anyone help because I stuck at this problem for more than a week.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.