How to bypass Cloudflare detection with Selenium PHP?

Hi, I work with Seleniu PHP to automate testing. But I can’t bypass Cloudflare loading page when open webpage, how to bypass it with Seleniu PHPunit? I have tried to add resetting the Selenium Driver script as below, but seems not working…

$handle = $this->webDriver->getWindowHandle();
ChromeDriverService::stop();
sleep(10);
$url = "https://". $GLOBALS['LT_USERNAME'] .":" . $GLOBALS['LT_APPKEY'] ."@hub.lambdatest.com/wd/hub";
$this->webDriver = RemoteWebDriver::create($url, $this->build_browser_capabilities());
$this->webDriver->switchTo()->window($handle);
$this->webDriver-quit();

You can reset the Selenium driver to bypass Cloudflare detection. After accessing the detection page of CloudFlare using Selenium, the Selenium Driver needs to be reset to bypass Cloudflare detection.

Resetting the code: Example (Python)

Thank you But, regarding your scripts, if I run Selenium Python tests on Cloud Selenium Grid, your script wont work,

driver.service.stop();

remote driver has not this attribute “service”.

Even if on local mechine to try with your script, somthing is wrong still tough…as below

Hello @kwaninmacau

I tried to open https://nowsecure.nl/ and it is opening fine at my end.

If you could please share the website you are testing. I will try to reproduce and share the solution with you

Thank you for your reply. I am trying to login this website Found surebets / SureBet - Professional betting , when you click “Log in” button on the top right , try to login, you will be paused by cloudflare detection. Could you share your python script?

Could you please share dummy credentials so that I can reproduce. Adding on, I did the same using PHP and it worked fine without adding anything extra

What is your PHP script? What do you need for my script?PHP script code or Python code?

I need login id and password for the website so that I can run the same at my end

No need to login, only when you can be directed to login page, you succeed. How do you get it? Could you share your scriptt?

Please find the code attached below:

$LT_USERNAME = getenv(“LT_USERNAME”);

# accessKey:  AccessKey can be generated from automation dashboard or profile section
$LT_ACCESS_KEY = getenv("LT_ACCESS_KEY");

$host= "http://". $LT_USERNAME .":" . $LT_ACCESS_KEY ."@hub.lambdatest.com/wd/hub";

$result="passed";

 $capabilities = array(
	"build" => "Sample PHP Build",
	"name" => "Sample PHP Test",
	"platform" => "Windows 10",
	"browserName" => "Chrome",
	"version" => "88.0"
 );
 
  try{
       $driver = RemoteWebDriver::create($host, $capabilities);
    
    $driver->get("https://en.surebet.com/surebets?utm_source=lambdatest-community");
  
    $element = $driver->findElement(WebDriverBy::cssSelector("a[href*='/users/sign_up']"));

    $element->click(); 
    } catch(Exception $e) {
        $result="failed";
        print  "Test failed with reason ".$e->getMessage();
    }
    finally{
        // finally quit the driver
        $driver->executeScript("lambda-status=".($result == "passed" ? "passed":"failed"));
        $driver->quit();
}
1 Like

Also the video link: LambdaTest Sharing

Thank you for your patience! What about clicking “Log in” button? By the way, sign up page has not added Cloudflare detection…

Let me check this. I will get back to you

1 Like

I am able to reproduce it and try to find a way to bypass it. Will keep you posted

1 Like