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,930 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 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 28, 2018 in Selenium by bug_seeker
• 15,350 points
0 votes
1 answer

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,090 points
0 votes
1 answer
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,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer
0 votes
2 answers

How to scroll down a webpage in selenium using Java?

This works... JavascriptExecutor jse = (JavascriptExecutor)driver; j ...READ MORE

answered Apr 3 in Selenium by anonymous