Unable to click a link in IE9

164 views
Skip to first unread message

ARK Satyanarayana Raju

unread,
Oct 8, 2013, 3:11:22 AM10/8/13
to seleniu...@googlegroups.com
Hi All,

   I tried to click a link in IE, but it is displaying Unable to find element. Can any one help me.

Windows7- IE9
My code is:


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class OpenIE {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.ie.driver","C:\\Users\\Downloads\\IEDriverServer.exe");
        WebDriver driver=new InternetExplorerDriver();
        driver.get("http://www.axisbank.com");
        Thread.sleep(5000);
        System.out.println("website launched successfully ");
        driver.findElement(By.linkText("About Us")).click(); 
        System.out.println("...........................");
        driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
        System.out.println(driver.getTitle());
        //driver.quit();
    }
}


Console:

Started InternetExplorerDriver server (32-bit)
2.33.0.0
Listening on port 26909
Oct 08, 2013 12:32:10 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
Oct 08, 2013 12:32:10 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
website launched successfully

Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20 milliseconds
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
Session ID: 4e998ba3-4aae-49b6-86cb-a659017bba84
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=9, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=, nativeEvents=true, browserAttachTimeout=0, takesScreenshot=true}]
    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.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:356)
    at org.openqa.selenium.By$ByLinkText.findElement(By.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
    at Practice_pack_1.OpenIE.main(OpenIE.java:17)

praveenreddy narala

unread,
Oct 8, 2013, 4:45:37 AM10/8/13
to seleniu...@googlegroups.com
Satyanarayana Rajum

Try this code for launching the IE browser...you will not get this exception

DesiredCapabilities
capabilities = DesiredCapabilities.internetExplorer(); capabilities.set(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); WebDriver driver = new InternetExplorerDriver(capabilities);

Message has been deleted

sidh...@gmail.com

unread,
Nov 15, 2014, 9:22:07 PM11/15/14
to seleniu...@googlegroups.com
Hi,

I am also facing this issue even after setting capabilities as mentioned.
can anyone help if you have solution to this.

Thanks,
Sidh

Mark Collin

unread,
Nov 16, 2014, 10:15:05 AM11/16/14
to seleniu...@googlegroups.com
Never use the desired capability suggested below, it will cause problems for you.

If you see anybody telling you to add that capability just ignore their advice, they obviously don’t understand the repercussions of asking you to do that.

Looking at the stack trace the window you are trying to interact with has been closed, are you providing the correct link to InternetExplorerDriver.exe?

This template may help you out:




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b34aa953-eee1-4989-bc96-32235949f79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sidh...@gmail.com

unread,
Nov 16, 2014, 3:34:42 PM11/16/14
to seleniu...@googlegroups.com
Hi Mark,
Thanks for the reply.

My application has login window, once i enter user and password and clicked on login button. It closes login window and opens a new window.

I am not able to switch to new window since parent window is automatically closed and it gives exception

Nov 14, 2014 4:13:55 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.name: userId)

org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 19 milliseconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'WACDTL03SB158H', ip: '141.204.60.169', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_29'
Session ID: f5477bc4-1f52-43f3-91ea-d5e6e6e65cef
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, enablePersistentHover=true, ignoreZoomSetting=false, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:22855/, handlesAlerts=true, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]

HTML tag for login button is as below:
<input onclick="javascript:login();" type="image" alt="login" src="images/bt_login.png" complete="complete"/>

Please help.

Thanks,
Sidh

sidh...@gmail.com

unread,
Nov 17, 2014, 7:29:11 PM11/17/14
to seleniu...@googlegroups.com
can anyone please help me.


My application has login window, once i enter user and password and clicked on login button. It closes login window and opens a new window.

I am not able to switch to new window since parent window is automatically closed and it gives exception

Below are the details:
Code :---

System.setProperty("webdriver.ie.driver", "C:\\Users\\sb158h\\Desktop\\Sidharth\\Eclipse\\Selenium\\IEDriverServer_Win32_2.44.0\\IEDriverServer.exe");

        wb =new InternetExplorerDriver();
   
        wb.get("http://d1tvt1z1.vci.att.com:1410/devonly/login/login.htm");
        WebDriverWait wdw=new WebDriverWait(wb, 90);
        wdw.until(ExpectedConditions.elementToBeClickable(By.name("userId")));
       
        Thread.sleep(100);
        wb.findElement(By.name("userId")).sendKeys("tm1084");

        parent=wb.getWindowHandle();
        System.out.println(parent);
        wb.findElement(By.xpath("//input[@alt='login']")).click();
           
        //    wb.switchTo().window(parent);
           
            Set<String> child =wb.getWindowHandles();
            System.out.println(child);
            int cnt =child.size();
            System.out.println("count " +cnt);
            for (String eachchild:child){
            if (!(eachchild.equals(parent)))
                {
                    System.out.println(eachchild);
                   
                    wb.switchTo().window(eachchild);
                    break;
                }
                        

            }
           

// Below userId is on newly opened window

            wdw.until(ExpectedConditions.elementToBeClickable(By.name("userId")));
            wb.findElement(By.name("userId")).sendKeys("tm1084");

-------------------------------------------------------------------------------------------------------

Execution Result :
Started InternetExplorerDriver server (32-bit)
2.44.0.0
Listening on port 45810
de737d52-2bdc-45b5-bb53-f0a3a11f7777
[de737d52-2bdc-45b5-bb53-f0a3a11f7777]
count 1
Nov 17, 2014 3:03:00 PM org.openqa.selenium.support.ui.ExpectedConditions findElement

WARNING: WebDriverException thrown by findElement(By.name: userId)
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30 milliseconds

Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'WACDTL03SB158H', ip: '141.204.60.169', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_29'
Session ID: b01a7d26-c8ee-4520-abb9-7caa50d271ee
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, enablePersistentHover=true, ignoreZoomSetting=false, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:45810/, handlesAlerts=true, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:425)
    at org.openqa.selenium.By$ByName.findElement(By.java:299)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:730)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:728)
    at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:130)
    at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:1)
    at org.openqa.selenium.support.ui.ExpectedConditions$17.apply(ExpectedConditions.java:528)
    at org.openqa.selenium.support.ui.ExpectedConditions$17.apply(ExpectedConditions.java:1)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
    at Script.Login.main(Login.java:69)
Nov 17, 2014 3:03:00 PM org.openqa.selenium.support.ui.ExpectedConditions findElement

WARNING: WebDriverException thrown by findElement(By.name: userId)
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3 milliseconds

Xiang Dong

unread,
Nov 17, 2014, 9:16:18 PM11/17/14
to seleniu...@googlegroups.com
Sleep for a while after you click link at first page.

            Set<String> child =wb.getWindowHandles();
            System.out.println(child);
            int cnt =child.size();
            System.out.println("count " +cnt);
            for (String eachchild:child){
            if (!(eachchild.equals(parent)))
                {
                    System.out.println(eachchild);
                    
                    wb.switchTo().window(eachchild);
                    break;
                }
                         

            }
above codes may not execute correctly, when you call Set<String> child =wb.getWindowHandles();, the second window may not open and you still get the first window, then the switch action does not actually performed, so, you may still in the first page and got NoSuchWindow exception.

Hope it works for you.

--David


Date: Mon, 17 Nov 2014 16:29:11 -0800
From: sidh...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Unable to click a link in IE9

sidh...@gmail.com

unread,
Nov 18, 2014, 2:27:28 PM11/18/14
to seleniu...@googlegroups.com

Thanks David and All for the help.
It worked after making thread to sleep for a while.

Thanks,
Sidh
Reply all
Reply to author
Forward
0 new messages