Getting the count from Search result

package package_name;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class class_name {
//The first letter of class name must be in Upper case
WebDriver driver;
public static void main(String[] args) {
System.setProperty(“webdriver.chrome.driver”,” path of driver/chromedriver.exe”);
//Starting the driver
ChromeDriver driver = new ChromeDriver();
// Expanding the browser
driver.manage().window().maximize();
// Getting the URL
driver.get(“https://www.bing.com/ “);
// Enter search keyword
driver.findElement(By.id(“sb_form_q”)).sendKeys(“Dhoni”);
// Clicking on enter button
driver.findElement(By.xpath(“.//*[@id=’sb_form_go’]”)).click();
//Getting and storing the text in a variable
String aaa= driver.findElement(By.xpath(“.//*[@id=’b_tween’]/span[1]”)).getText();
//Displaying result
System.out.println(aaa);
//Closing the driver
driver.close();
}
}

Leave a comment