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
}
}
-
Not able to locate Search button of google search– JD_DeveloperCommented Feb 5, 2017 at 8:02
6 Answers
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);
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.
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();
Right Answer is
driver.get("https://www.google.com");
driver.findElement(By.id("lst-ib")).sendKeys("Selenium");
driver.findElement(By.id("_fZl")).click();
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 :)