Finding 99th link if 100 links are present in the page | Selenium Forum
A
Avijeet Posted on 16/03/2019

IF we have 100 links  in a web page how to click on 99th link.

I'm able to find all links but unbable to click on link based on linktext. While trying below code getting elementnot visible exception.

 

cd.get("http://timesofindia.com");

List<WebElement> lst=cd.findElements(By.tagName("a"));

System.out.println(lst.size());

for(int i=0;i<=lst.size()-1;i++) {

if (i==99)
lst.get(i).click();
else

 


A
Ashish Thakur Replied on 18/03/2019

You need to scroll the page before clicking that link


A
Avijeet Replied on 18/03/2019

1> Should tht code will work??

2> Whats the reason we need to scroll the page?

 


A
Ashish Thakur Replied on 19/03/2019

The element you want to click is not visible on the screen, to make it visible, you need to scroll the page before clicking


A
Avijeet Replied on 09/04/2019

thanks , its working fine.Hence can be closed.