Skip to main content

Clicking the Web Element and Scraping the Details

Hi, guys in this Tutorials I am going to show you how to click a web element and scrap the details.

Follow the below steps 

1. Create a Java project and download the jars selenium-server-standalone-2.41.0.jar

2.Add the downloaded Jar in your project.

3.Download the Chrome Drive for use in the program below.

4 Create the program for scraping

  1. import java.util.List;
  2. import org.openqa.selenium.By;
  3. import org.openqa.selenium.Keys;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.chrome.ChromeDriver;
  7. public class Demo1 {
  8. public static void main(String[] args) throws InterruptedException {
//first paramter is driver name and second is driver's path
  1. System.setProperty("webdriver.chrome.driver",
  2. "C:\\New_Teslra\\DemoTipschromedriver\\chromedriver.exe");
  3. WebDriver driver = new ChromeDriver();
  4. driver.get("http://google.co.in");
  5. driver.findElement(By.name("q")).sendKeys("customizing surefire reports");
  6. driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
  7. Thread.sleep(5000);
  8. List<WebElement> list = driver.findElements(By.className("rc"));
  9. System.out.println("List"+list);
  10. for(WebElement element:list)
  11. {
  12. System.out.println(element.findElement(By.xpath(".//h3")).getText());
  13. //*[@id="rso"]/div/div/div[1]/div/div/h3
  14. //*[@id="rso"]/div/div/div[1]/div/div/h3
  15. //#rso > div > div > div:nth-child(1) > div > div > h3
  16. //System.out.println(element.findElement(By.tagName("h3")).getText());
  17. }
  18. //link.click();
  19. Thread.sleep(10000);
  20. driver.quit();
  21. }
  22. }


Comments

Popular posts from this blog

Mastering Java Logging: A Guide to Debug, Info, Warn, and Error Levels

Comprehensive Guide to Java Logging Levels: Trace, Debug, Info, Warn, Error, and Fatal Comprehensive Guide to Java Logging Levels: Trace, Debug, Info, Warn, Error, and Fatal Logging is an essential aspect of application development and maintenance. It helps developers track application behavior and troubleshoot issues effectively. Java provides various logging levels to categorize messages based on their severity and purpose. This article covers all major logging levels: Trace , Debug , Info , Warn , Error , and Fatal , along with how these levels impact log printing. 1. Trace The Trace level is the most detailed logging level. It is typically used for granular debugging, such as tracking every method call or step in a complex computation. Use this level sparingly, as it can generate a large volume of log data. 2. Debug The Debug level provides detailed information useful during dev...

Choosing Between Envoy and NGINX Ingress Controllers for Kubernetes

As Kubernetes has become the standard for deploying containerized applications, ingress controllers play a critical role in managing how external traffic is routed to services within the cluster. Envoy and NGINX are two of the most popular options for ingress controllers, and each has its strengths, weaknesses, and ideal use cases. In this blog, we’ll explore: How both ingress controllers work. A detailed comparison of their features. When to use Envoy vs. NGINX for ingress management. What is an Ingress Controller? An ingress controller is a specialized load balancer that: Manages incoming HTTP/HTTPS traffic. Routes traffic to appropriate services based on rules defined in Kubernetes ingress resources. Provides features like TLS termination, path-based routing, and host-based routing. How Envoy Ingress Controller Works Envoy , initially built by Lyft, is a high-performance, modern service proxy and ingress solution. Here's how it operates in Kubernetes: Ingress Resource : You d...

Understanding API Parameters in Spring Boot

Understanding API Parameters in Spring Boot When designing APIs in Spring Boot, it's essential to understand how to handle different types of parameters. These parameters define how data is sent from the client to the server. Let's break down the common types of parameters used in API development, with examples and cURL commands. 1. Types of Parameters Parameter Type Location Use Case Example Format Annotation in Spring Boot Query Param URL after `?` Filtering, Pagination ?key=value @RequestParam Path Param In the URL path Identifying specific resource /resource/{id} @PathVariable Form Param Form-encoded body Simple form submissions ...