The below code fetches string present inside all the buttons present inside "Google.com" Home page.
/* There is a peculiar scenarion I encountered while working this scenario, where the buttons actually present is 2 but we get totla of 3 buttons by running the code -- We figured out what the button was , hope u'll find too */
import
import
javax.swing.JOptionPane;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.support.events.EventFiringWebDriver;
public
class Google
{
{
String frnd;
WebDriver driver=
new FirefoxDriver();
EventFiringWebDriver d=
new EventFiringWebDriver(driver);
d.get(
"http://www.google.co.in/");
WebElement box = d.findElement(By.id(
"gsr"));//id("mngb"));
List names =box.findElements(By.tagName(
"button"));
JOptionPane.showMessageDialog(
null, "names.size()="+names.size());
{
{
System.
out.println(((WebElement) names.get(i)).getText()+" "+i);
}
{
System.
out.println("---CONTAINS empty Space");
}
{
System.
out.println("Contains null button");
}
{
System.
out.println(((WebElement) names.get(i)).getAttribute("id")+"---"+i);
}
}
d.quit();
}
}
//for (int i=0 ; i< names.size(); i++)
//{
// frnd=names.get(i).getText();
// //JOptionPane.showMessageDialog(null, "hi");
// System.out.println( ((WebElement) names.get(i)).getText());
//}
//JOptionPane.showMessageDialog(null, a);
//Thread.sleep(5000L);
No comments:
Post a Comment