How to search for a keyword in google using selenium Java

+2 votes
I am new to selenium and I have started from ground level and working with chrome and I am able to open google. Now my question is how to search for a keyword there?
Dec 17, 2018 in Selenium by Anjali
• 2,950 points
how to avoid the pop-up window in chrome browser.

when every i run my script it's open the chrome browser it'showing pop-up like.

browser or delete search activity data.

it's displaying the two buttons like "no thanks" and "show me" buttons .

this my code please any solution help me to overcome the problem.

public static void main(String[] args) throws InterruptedException {

System.setProperty("", "C:\\softwares\\selenium\\webdrivers\\chromedriver.exe");

WebDriver driver=new ChromeDriver();



driver.findElement(By.className("gb_1 gb_nd gb_od")).click();



Hi @Naresh, please checkout this link. I have created a new thread for your problem, so that it can be properly seen and answered by others:

1 answer to this question.

+2 votes
Best answer

You can use locators to find the textbox and then search for a keyword you like. 

1. Open Google and right click to inspect element. You can use F12 also to inspect elements.


2. Go to the searchbox and inspect the web element you can use for your purpose.

You can see that there is a name field, I will use it for finding the search box.

Here is the code that I am using:

WebDriver wd = new ChromeDriver();//create an instance for webdriver named wd of type chrome
wd.get("");//open google
WebElement elem = wd.findElement("q"));//finding the web element using name locator
elem.sendKeys(new String[]{"selenium is fun"});


answered Dec 17, 2018 by Nabarupa

selected Aug 26, 2019 by Abha

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 29, 2018 in Selenium by bug_seeker
• 15,550 points
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

How to print all google suggestions for a keyword using Selenium Webdriver?

Hello Cherry, below is the automation script ...READ MORE

answered May 23, 2019 in Selenium by Abha
• 28,060 points
0 votes
5 answers

How to scroll down a webpage in selenium using Java?

 to scroll up or down with Selenium, a JavaScript executor is a ...READ MORE

answered Dec 16, 2020 in Selenium by Roshni
• 10,480 points