How to use WebDriver (Chromium) with extension for test automation
Hello:
In my previous project, I could use Puppeteer-Sharp to automatically login to one web site.
However, at the end of year 2020, after this web site used hcaptcha, then my code stopped working.
But I found I can login by using current version of WebView2. However, the every two hours, the hcaptcha will appear again, then I have to solve the challenge again. But the web site said people can install Privacy Pass Chrome extension to reduce the times you have to solve the challenge. For example, if you solved challenge once by hand, then you got credit of 5, therefore, for next 5 times, you don’t have to solve the challenges again and again. In short, for one manually solved challenge, you can have up to 10 hours without do this again.
I wanted to see if I can use the Privacy Pass extension in Edge browser, from my testing, it works very well. The web site is: https://buff.bet/
So I have done the following:
- I used the online tools to extract and download the Privacy Pass Chrome extension from https://crxextractor.com/ and save the extracted CRX file in my PC. The web link for privacy pass extension in Google web store is:
https://chrome.google.com/webstore/detail/privacy-pass/ajhmfdgkijocedmfjonnpjfojldioehi - I also visited Microsoft Edge Driver downloads page and downloaded version 88.0.705.53, which is the version of my current Edge version; and unzip it and save it in my PC.
- I don’t quite understand how and why I should install the latest version of Selenium is 4.00-alpha07. Besides, when I installed it using this command:
Install-Package Selenium.WebDriver -Version 4.0.0-alpha07
I can see it has some issue with my C# project, which is Windows Form App (.Net) target .net 5.0.
So, I didn’t install this Nuget package.
The following is my C# code: (IDE: Visual Studio 2019 Version 16.8.4 On Windows 10 Version 20H2)
using Microsoft.Edge.SeleniumTools;
using System;
using System.Windows.Forms;
namespace SeleniumForm1
{
public partial class Form1 : Form
{
public const string EdgeDriverFile =
@"C:\WebDriver\SeleniumForm1\SeleniumForm1\edgedriver_win64_70553\";
public const string PrivacyPassCRX =
@"C:\WebDriver\SeleniumForm1\SeleniumForm1\crx\privacypass.crx";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
EdgeOptions edgeOptions = new EdgeOptions
{
UseChromium = true,
BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
};
edgeOptions.AddExtensions(PrivacyPassCRX);
EdgeDriver driver = new EdgeDriver(EdgeDriverFile, edgeOptions);
driver.Navigate().GoToUrl("https://buff.bet/");
}
}
}
I can run my program, however, this issue is: the web site keeps showing challenges again and again without ending even I solve all the challenges by hand, I can see the credit count has dropped from 5 to 0, then I have to solve the challenges again.
However, if I used WebView2 in C# program and solved the challenges by hand, then I could easily visit the web site, but for only 2 hours.
Any suggestions? How I can use web drive with Privacy Pass extension just as I can use it in Edge browser and got 5 credit count?