• Tech Travel Hub is your one stop, ultimate tour guide to all things tech, travel, visas and digital nomads
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
Menu
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
View Blog
May 6, 2023May 6, 2023

How To Search Using Google and Click on a Specific Link Using Selenium?

To start with selenium learning, the first step I suggest is to automate google. In this exercise i will try to show how to automate google.

The objective of this post is to automate a flow where steps are-

  1. open a firefox browser 
  2. Navigate to google. 
  3. in the search box type askqtp. 
  4. Click on search
  5. list the links available in the search
  6. Click on the first link
  7. Read the title. 

for this


//Normal imports
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class ClickaLink {

public static void main(String[] args) {
//Creating the web driver
WebDriver fd=new FirefoxDriver();
//Step 1&2
fd.get("http:\google.com");
fd.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
//Step-3
fd.findElement(By.xpath("//input[@class='gbqfif']")).sendKeys("askqtp");
//step-4
fd.findElement(By.xpath("//*[@id='gbqfb']")).click();
WebElement box=fd.findElement(By.xpath("//*[@id='res']"));
//the center box in the results page that has all the links Step-5
List<WebElement>allLinks=box.findElements(By.xpath("//*[@id='rso']/li/div/h3/a"));
//xpath of the links displayed

System.out.println("Total Links -->" allLinks.size());
for(int i=1;i<allLinks.size();i++ ){
System.out.println(allLinks.get(i).getText());
//Step-6
allLinks.get(1).click();
//click on the first link that is displayed
}
}

By this code you will be able to click on the firstlink and automate google search. Hope this helps.

Post navigation

Previous post
Next post

Umer Umer

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 5 Ultimate Dental Nightmares and How to Avoid Them
  • 7 Alarming Facts on Early And Late Dental Implant Complications
  • The Skinny Jean Is Dead: The 5 Denim Styles You Need Now
  • 5 Reasons Why The Demand For Digital Marketing Courses Is Unstoppable At This Moment?
  • 3 Delicious Facts About Cakes That Very Few People Know

Categories

  • Adventure
  • Agile Methodology
  • All world Tour
  • Android Development
  • Ansible
  • App
  • App Development
  • Artificial Intelligence
  • AWS
  • Bitcoin
  • BlockChain
  • Blogging
  • Box Packing
  • Business
  • business
  • Business Communication
  • buying guide
  • C
  • car
  • Care
  • Certification
  • Certification
  • Chatbot
  • cinema
  • Cloud Tech
  • Content Marketing
  • Corporate
  • covid-19
  • crucible
  • Cryptocurrency
  • Database
  • DevOps
  • DevOps
  • Digital Marketing
  • Drawing
  • Dress
  • Educational
  • Employment
  • Entertainment
  • Exceptions In Java
  • Fashion
  • Festivals
  • Finance
  • Fitness
  • Food
  • Game
  • Gift ideas
  • Groovy
  • Health
  • Health
  • home
  • home improvement
  • HR
  • IllegalThreadStateException in Java
  • India Tour
  • Instagram
  • Ios
  • ISO
  • Java
  • Javascript
  • job
  • Kids Section
  • Kitchen
  • Law
  • Life Style
  • Lifestyle
  • Lifestyle Home Improvement
  • Main Stories
  • Management
  • Mattress
  • Motorable
  • Movie
  • nursing
  • Pendrive
  • Perspective
  • Pet
  • Popular
  • Programming
  • Python
  • Relationships
  • Selenium
  • SEO
  • Skin
  • SOAPUI
  • Social Media
  • Social Media Marketing
  • Software
  • software development
  • Software Development Model
  • Software Engineering
  • Software Testing
  • Sports
  • Startup
  • T Robot
  • TDD
  • Tech
  • Tech News
  • Tech News
  • Technology
  • Tool
  • Tour Guide
  • Tour Guide
  • Travel
  • UFT
  • Uncategorized
  • USB Cable
  • VPN
  • Web Development
  • Wordpress
  • Yoga
  • Youtube

Tags

Instagram Instagram Marketing Marketing SEO Thoptv App

Categories

  • Tech
  • Travel
  • Visas
  • Digital Nomad
  • Tech
  • Travel
  • Visas
  • Digital Nomad

Publishing

If you would like to publish on our site, please email admin@techtravelhub.com

Quick Links

  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact

Contact

Tech Travel Hub LLC

Address:
8 The Green STE A
Dover
Delaware, 19901

Phone: +1 302 956 9948