Category Archives: Uncategorized

Use Selenium Webdriver on Ubuntu with .NET Core 7

First update your system

apt update
apt upgrade

Next download google-chrome

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

Next install ‘google-chrome’

dpkg -i google-chrome-stable_current_amd64.deb

If you have a problem with your dependencies after the previous step, run the following command then try again the previous step.

sudo apt -f install

Verify your version of google-chrome

google-chrome --version
# Google Chrome 123.0.6312.86

Create a new console program

dotnet new console -n SeleniumExample
cd SeleniumExample

Install required packages

dotnet add package Selenium.WebDriver
dotnet add package Selenium.WebDriver.ChromeDriver

Edit your Program.cs file and replace its contents with the code below.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program
{
    static void Main(string[] args)
    {
        // Set up the ChromeDriver
        var options = new ChromeOptions();
        options.AddArgument("--headless");

        using var driver = new ChromeDriver(options);

        // Navigate to a website
        driver.Navigate().GoToUrl("https://www.google.com");

        // Wait for the results to load and display the title
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        Console.WriteLine(driver.Title);

        // Close the browser
        driver.Quit();
    }
}

Run the program, it should show the title of the google.com webpage

Share

Set static IP on Ubuntu 24.04

First check your current ip and gateway settings with the command “ip a” and “ip r”.

Edit the file /etc/netplan/00-installer-config.yaml, place the following contents in it:

network:
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 172.29.0.2/24
      nameservers:
        addresses: [1.1.1.1,8.8.8.8]
      routes:
        - to: default
          via: 172.29.0.1
  version: 2

The gateway address can be determined by executing ip r

Share

Multilangual MVC application

Create a new ASP.Net MVC application

Add a Resources folder and add two files with this folder:
Views.Home.Index.en.resx
Views.Home.Index.nl.resx

Add an entry WelcomeText to both files. With a dutch value in the nl.resx file and an english value in the en.resx file.

Now update your startup.cs to support multiple languages. Edit your Program.cs in the root of the project file. Add this code right before var app = builder.Build();

// Add services to the container.
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddControllersWithViews()
    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
    .AddDataAnnotationsLocalization();

builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");

builder.Services.Configure<RequestLocalizationOptions>(options =>
{
    var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("nl") };
    options.DefaultRequestCulture = new RequestCulture("en");
    options.SupportedCultures = supportedCultures;
    options.SupportedUICultures = supportedCultures;
});

And this code right before app.Run();

var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("nl") };
var localizationOptions = new RequestLocalizationOptions
{
    DefaultRequestCulture = new RequestCulture("en"),
    SupportedCultures = supportedCultures,
    SupportedUICultures = supportedCultures
};

app.UseRequestLocalization(localizationOptions);

That’s it. Now you can switch between languages by adding ?culture=en or ?culture-nl to your url.

Share