Handling button tag in selenium webdriver

Viewed 94

In Red bus app i am trying to click on search buses button,I tried in many ways like this

driver. find element(by. xpath("//button"(contains(text()='Search Buses')")).click();

still getting unable to locate the element anyone having solution for this.

1 Answers

Actually your attempted xpath syntax is incorrect. You should try as below :

driver.findElement(By.xpath("//button[contains(text(),'Search Buses')]")).click();

or

driver.findElement(By.xpath("//button[text()='Search Buses']")).click();

You can find it using By.id() as well which would be much faster than xpath as :

driver.findElement(By.id("search_btn")).click();

Follow these links to learn more about xpath

  1. https://www.w3schools.com/xml/xpath_intro.asp
  2. https://www.w3schools.com/xml/xpath_syntax.asp
  3. https://www.w3schools.com/xml/xpath_axes.asp
Related