Wednesday, April 30, 2025

Chat locally using gpt4all application

 To chat locally using the GPT4All application, you must download and set up the GPT4All desktop app or run it from source. Here’s a general guide to help you get started:

Step-by-Step: Use GPT4All Locally

  1. Download the GPT4All App:

    • Go to https://gpt4all.io.

    • Click Download, and choose your operating system (Windows, macos, or Linux).

  2. Install and Launch:

    • Run the installer and follow the prompts.

    • Launch the GPT4All app after installation.

  3. Download a Model:

    • Upon first launch, the app will prompt you to download a local LLM (e.g., Mistral, LLaMA, or GPT-J variants).

    • Choose a model based on your system's capabilities (larger models may require more RAM).



  4. Start Chatting:

    • After the model loads, you can chat with it offline, directly on your machine.

  • Recorded Session by using lLama 3.1 8B Instruct 128k model


🧠 Things to Know

  • GPT4All runs fully offline, so no internet is needed after model download.

  • Performance depends on your system—older machines may struggle with larger models.

  • It's not GPT-4—it's a locally run LLM with decent capabilities but not on par with OpenAI’s GPT-4.

Thursday, April 10, 2025

Selenium Java - Warning/Errors and its solutions


Here's a list of standard warnings/errors in Selenium with Java and their respective solutions to help you debug faster and develop cleaner automation scripts.

✅ 1. org.openqa.selenium.NoSuchElementException

Cause: Trying to locate an element that does not exist on the page.

Solutions:

  • Ensure the element is present in the DOM and visible.

  • Add waits:

    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
    
  • Check locator correctness (id, xpath, cssSelector, etc.).


✅ 2. ElementNotInteractableException

Cause: Element is present but cannot be interacted with (e.g., it's hidden or disabled).

Solutions:

  • Use WebDriverWait to ensure it is clickable:

    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
    
  • Scroll into view using JavaScript:

    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
    

✅ 3. TimeoutException

Cause: Wait timed out before condition was met.

Solutions:

  • Increase wait time or optimize locator.

  • Use appropriate expected condition (e.g., presenceOfElementLocated vs visibilityOfElementLocated).


✅ 4. StaleElementReferenceException

Cause: WebElement is no longer attached to the DOM.

Solutions:

  • Re-locate the element after page reload or DOM change:

    element = driver.findElement(By.id("elementId"));
    
  • Use a try-catch block to retry locating the element.


✅ 5. SessionNotCreatedException

Cause: Browser version mismatch with WebDriver.

Solutions:

  • Make sure ChromeDriver/GeckoDriver matches your browser version.

  • Use WebDriverManager (for Maven):

    WebDriverManager.chromedriver().setup();
    

✅ 6. WebDriverException: unknown error: DevToolsActivePort file doesn't exist

Cause: Usually in headless mode with Chrome on Linux.

Solutions:

  • Add Chrome options:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--no-sandbox");
    options.addArguments("--disable-dev-shm-usage");
    options.addArguments("--headless");
    

✅ 7. Deprecation Warnings

Cause: Some older APIs (like Thread.sleep, implicitlyWait without Duration, etc.) are deprecated.

Solutions:

  • Replace deprecated code:

    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    

✅ 8. java.lang.NullPointerException

Cause: WebElement or WebDriver not initialized.

Solutions:

  • Check initialization:

    WebDriver driver = new ChromeDriver(); // Not null
    
  • Ensure correct scope in frameworks like TestNG, JUnit, etc.


✅ 9. org.openqa.selenium.ElementClickInterceptedException

Cause: Another element overlays the clickable element (like a modal or popup).

Solutions:

  • Wait for overlay to disappear.

  • Use JS click:

    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
    

✅ 10. IllegalStateException: The driver executable does not exist

Cause: Path to WebDriver not set correctly.

Solutions:

  • Set system property or use WebDriverManager:

    System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
    

Monday, April 7, 2025

Programming with Java using Notepad

EXAMPLE : ReversedString








Output





Programming in Java using Notepad is a simple way to get started with Java development without the need for an Integrated Development Environment (IDE). Below is a step-by-step guide to writing, compiling, and running a Java program using Notepad:

Step 1: Install Java Development Kit (JDK)

  1. Download and install the latest version of the JDK from the Oracle website or OpenJDK.
  2. During installation, note the installation directory (e.g., C:\Program Files\Java\jdk-XX.X.X).
  3. Set up the Environment Variables:
    • Add the bin directory of the JDK to the PATH variable:
      • Go to Control Panel > System > Advanced System Settings > Environment Variables.
      • Under "System Variables," find Path, click Edit, and add the path to the JDK's bin folder (e.g., C:\Program Files\Java\jdk-XX.X.X\bin).
  4. Verify the installation:
    • Open Command Prompt and type:
      1java -version
      2
      You should see the installed Java version.

Step 2: Write a Java Program

  1. Open Notepad (or any text editor).
  2. Write your Java code. For example, a simple "Hello, World!" program:
    1public class HelloWorld {
    2    public static void main(String[] args) {
    3        System.out.println("Hello, World!");
    4    }
    5}
    6
  3. Save the file with a .java extension:
    • File name must match the class name (e.g., HelloWorld.java).
    • Save it in a directory of your choice (e.g., C:\JavaProjects).

Step 3: Compile the Java Program

  1. Open Command Prompt.
  2. Navigate to the directory where you saved the .java file:
    1cd C:\JavaProjects
    2
  3. Compile the Java program using the javac command:
    1javac HelloWorld.java
    2
    • If there are no errors, this will generate a HelloWorld.class file in the same directory.

Step 4: Run the Java Program

  1. Run the compiled program using the java command:
    1java HelloWorld
    2
  2. You should see the output:
    1Hello, World!
    2

Tips and Best Practices

  • Indentation and Formatting: Use proper indentation to make your code readable.
  • Error Handling: If you encounter errors during compilation, carefully read the error messages to identify and fix issues.
  • Use Notepad++: For a better experience, consider using Notepad++, which provides syntax highlighting and other helpful features for coding.

Example Workflow

  1. Write the program in Notepad:
    1public class MyProgram {
    2    public static void main(String[] args) {
    3        System.out.println("Java programming is fun!");
    4    }
    5}
    6
  2. Save it as MyProgram.java.
  3. Open Command Prompt, navigate to the file's directory, and compile it:
    1javac MyProgram.java
    2
  4. Run the program:
    1java MyProgram
    2
    Output:
    1Java programming is fun!
    2

By following these steps, you can successfully write, compile, and run Java programs using Notepad