Reputation: 75
I am setting up a test to perform a search and after the search is complete, i want to capture the results line that says "About xxx results (x.xx seconds)" Here's the code snippet
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://google.com");
driver.manage().window().maximize();
WebElement searchBox = driver.findElementById("lst-ib");
searchBox.sendKeys("search text");
WebElement clickSearch = driver.findElementByXPath("html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[2]/div/div/div/button");
clickSearch.click();
WebElement results = driver.findElementByXPath("html/body/div[1]/div[5]/div[4]/div[5]/div[1]/div[1]/div/div/div");
System.out.println(results);
Upvotes: 0
Views: 528
Reputation: 4173
The line you need to capture would have the selector:
Css:
#resultStats
Xpath:
//div[@id='resultStats']
If you need to return the text:
//div[@id='resultStats']//text()
Or use find and getText() method.
Upvotes: 0
Reputation: 4832
You need to use getText()
method to get the text form a element. In your case you need to do something like below,
WebElement results = driver.findElement(By.xpath("html/body/div[1]/div[5]/div[4]/div[5]/div[1]/div[1]/div/div/div"));
System.out.println(results.getText());
Upvotes: 1