As per the HTML you have shared to locate the Search Buses button and invoke click()
you can use either of the following line of code :
-
cssSelector
driver.findElement(By.cssSelector("button.fl.button#search_btn")).click();
-
xpath
driver.findElement(By.xpath("//button[@class="fl button" and @id='search_btn']")).click();
Update
With Selenium-Java Client v3.9.1 , GeckoDriver v0.19.1 and Firefox Quantum v58.0.2 this block of code works perfect at my end :
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.redbus.in/");
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.fl.button#search_btn"))).click();
System.out.println("Search button clicked");
driver.quit();
Console Output :
Search button clicked
Snapshot :
6
solved I am having trouble in locating search bus button in red bus site using selenium webdriver with java