0% found this document useful (0 votes)
27 views1 page

As

The document is a Java program that automates spell-checking on a specified website using Selenium WebDriver and LanguageTool. It launches a Chrome browser, retrieves the page source, extracts visible text, and checks for spelling errors. If errors are found, it provides details about the errors and suggestions for corrections.

Uploaded by

vamshi kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

As

The document is a Java program that automates spell-checking on a specified website using Selenium WebDriver and LanguageTool. It launches a Chrome browser, retrieves the page source, extracts visible text, and checks for spelling errors. If errors are found, it provides details about the errors and suggestions for corrections.

Uploaded by

vamshi kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import org.openqa.selenium.

WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.languagetool.JLanguageTool;
import org.languagetool.language.BritishEnglish;
import org.languagetool.rules.RuleMatch;

import java.util.List;

public class SpellCheckAutomation {


public static void main(String[] args) {
// Set the path to your WebDriver executable
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

// Launch the browser and open the website


WebDriver driver = new ChromeDriver();
String url = "https://yourwebsite.com"; // Replace with your website URL
driver.get(url);

// Fetch page source


String pageSource = driver.getPageSource();
driver.quit(); // Close the browser

// Parse text from the page using JSoup


Document doc = Jsoup.parse(pageSource);
String visibleText = doc.text(); // Extract visible text

// Initialize LanguageTool for spell-checking


JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
try {
List<RuleMatch> matches = langTool.check(visibleText);

if (matches.isEmpty()) {
System.out.println("No spelling errors found!");
} else {
System.out.println("Spelling errors detected:");
for (RuleMatch match : matches) {
System.out.println("Potential Error: " + match.getMessage());
System.out.println("Suggestions: " +
match.getSuggestedReplacements());
System.out.println("At position: " + match.getFromPos() + " - "
+ match.getToPos());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

<dependency>
<groupId>org.languagetool</groupId>
<artifactId>languagetool-core</artifactId>
<version>5.9</version> <!-- Or latest version -->
</dependency>

You might also like