To check whether the object is visible using the previous concept
import java.sql.Driver;
import java.util.List;
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
{
public static void main(String[] args) throws InterruptedException
{
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());
for (int i=0 ; i<names.size();i++ )//(WebElement) names.get(i)).getText() != null ||
{
if ( ((WebElement) names.get(i)).isDisplayed() == true )//(((WebElement) names.get(i)).getText().length()>2) //box.findElement(By.xpath("xpathExpression")).//isDisplayed()
{
System.out.println(((WebElement) names.get(i)).getText()+" "+i);
}
else if (((WebElement) names.get(i)).isDisplayed() == false )//(box.findElement(By.tagName("button")).isDisplayed() == false ) //(((WebElement) names.get(i)).getText().length()<=2)
{
System.out.println(((WebElement) names.get(i)).getAttribute("id")+"---Not displayed "+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