2
package selrcdemo;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By.ById;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.Assert;

public class rcdemo {
   // TODO Auto-generated method stub

    public static void main(String[] args) {

    WebDriver driver; // declare webdriver instance
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\Cheitrav\\Desktop\\ISTQB\\chromedriver.exe"); // set driver path
    driver =new ChromeDriver(); // instantiate new firefox driver

    driver.get("https://www.google.com"); // open google.com

    driver.findElement(By.id("lst-ib")).sendKeys("Selenium");

    //Insert code here to locate and click on Search button


    }

}
1
  • Not able to locate Search button of google search Commented Feb 5, 2017 at 8:02

6 Answers 6

4

You can use linkText to find the search button on the Google Search page.

driver.findElement(By.linkText("Google Search")).click();

you can also search by simulating Enter Button click on the search text box, after entering the text to search.

driver.findElement(By.id("lst-ib")).sendKeys(Keys.RETURN);
1

You can use a css selector like:

input[type=submit]

or

input[name=btnK]

or

form input[type=submit]

Or you can try to search by name btnK in case it will never change.

0

you can use the below code to click on the search button.

//Insert code here to locate and click on Search button
driver.findElement(By.name("btnK")).click();
0

Right Answer is

driver.get("https://www.google.com");

driver.findElement(By.id("lst-ib")).sendKeys("Selenium");

driver.findElement(By.id("_fZl")).click();
0
0

You dont have to be click, you can take page with "submit"

For example;

search_box = driver.find_element_by_name('q') search_box.send_keys("keyword") search_box.submit()

and then browser goes to results :)

-1

You can use XPath like:

(//input[@value='Google Search'])[2]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.