ElementNotInteractableException on navigating to all the header links in CNNcom example in Day8 | Selenium Forum
V
Vijayalakshmi Posted on 03/01/2019
package day8;

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

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CNN {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "D:\\Selenium_Learning\\firefox.txt");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://edition.cnn.com/");
WebElement box = driver.findElement(By.xpath("/html/body/div[5]/div[2]/div[2]/div[2]"));
List<WebElement> links = box.findElements(By.tagName("a"));
System.out.println("Total Links "+links.size());
for(int i=0;i<links.size();i++) {
System.out.println(links.get(i).getText());
links.get(i).click();
System.out.println(driver.getTitle());
box = driver.findElement(By.xpath("/html/body/div[5]/div[2]/div[2]/div[2]"));
links=box.findElements(By.tagName("a"));
System.out.println("------------------------------------");
}

}

}

Error:
looping through for loop is successful. It clicked on each link and printed the webpage title but after printing the last link details got an exception as shown below

Total Links 9
World
World news – breaking news, videos and headlines - CNN
------------------------------------
World
World news – breaking news, videos and headlines - CNN
------------------------------------
U.S.
US News – Top national stories and latest headlines - CNN
------------------------------------
Africa
Africa news - breaking news, video, headlines and opinion - CNN
------------------------------------
Americas
Americas news - breaking news, video, headlines and opinion - CNN
------------------------------------
Asia
Asia news - breaking news, video, headlines and opinion - CNN
------------------------------------
Australia
Australia news - breaking news, video, headlines and opinion - CNN
------------------------------------
China
China news - breaking news, video, headlines and opinion - CNN
------------------------------------
Europe
Europe news - breaking news, video, headlines and opinion - CNN
------------------------------------
Middle East
Middle East news - breaking news, video, headlines and opinion - CNN
------------------------------------
UK
UK news - breaking news, video, headlines and opinion - CNN
------------------------------------

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <a class="nav-menu-links__link" href="/world"> could not be scrolled into view
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'VIJI-PC', ip: '192.168.1.100', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 63.0.3, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 6572, moz:profile: C:\Users\Viji\AppData\Local..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 6.1, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: a9abbaf0-372e-4684-a531-037ed426ef2b
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at day8.CNN.main(CNN.java:24)


A
Ashish Thakur Replied on 04/01/2019

You have to use actions class and scroll down to that element so that it comes to the screen view