Links text and is dispalyed functionality not working | Selenium Forum
M
Posted on 01/12/2015
Code:


import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.fluent.Request;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Flipkart {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.flipkart.com/");
driver.findElement(By.xpath("//*[@id='fk-mainhead-id']/div[2]/div/div/ul/li[2]/a/span")).click();
WebElement box=driver.findElement(By.xpath("//*[@id='menu-men-tab-0-content']/ul[1]"));
List<WebElement> allLinks =box.findElements(By.tagName("a"));
System.out.println(allLinks.size());
for (int i=0;i<6;i++)

{
System.out.println(allLinks.get(i).getText()+"-----------"+allLinks.get(i).isDisplayed());

}




output:

16
-----------false
-----------false
-----------false
-----------true
Formal Shoes-----------true
Sandals & Floaters-----------true




Question: 1 . I run same program many times in chrome and each time response is different? why

2. Why ..... false is coming when we have links displayed also and text is also there

Screenshot attached

M
Replied on 01/12/2015

to retrieve them you have to use actions class. because they are hidden elements.


M
Replied on 01/12/2015

I agree,



Here is the output again on running same program


16

-----------false
-----------false
-----------false
-----------false
-----------false
-----------false


Previous result:
Formal Shoes-----------true
Sandals & Floaters-----------true


Now these are coming .........false.


Howcome?? can visible links became hidden in 2hr? is it right


M
Replied on 02/12/2015

watch actions class module 15 and everything will be clear.