Selenium WebDriver Not Finding Elements

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Selenium WebDriver Not Finding Elements

Justin O'Connor
I started having issues with Selenium being able to detect elements on a page.  Up until yesterday this code worked just fine, but something seems to have changed causing the WebDriver to timeout versus finding the Element.  I tried modifying the code to point to google.com and bing.com and search for the Name("q"), but it's not picking it up.

I'm using Internet Explorer 11 for this.  Has anyone else come across this before?
It's worth noting that I rolled back to the previous drivers in case an updated driver caused the problems (even though there hasn't been one published since last month), but the results remain the same.

I set the timeout for 10 seconds to give the page a chance to fully load, otherwise I would throw an exception.

namespace SeleniumTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var _ieOptions = new InternetExplorerOptions();
            _ieOptions.IgnoreZoomLevel = true;
            var _driver = new InternetExplorerDriver(_ieOptions);
            //var __driver = new ChromeDriver();

            var _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
            _driver.Navigate().GoToUrl("http://172.16.3.163:163/Execute/Display");


            _wait.Until(ExpectedConditions.ElementExists(By.Name("UserId")));
            _driver.FindElement(By.Name("UserId")).SendKeys("Google");
                   
        }
    }
}




Here's the error.
OpenQA.Selenium.WebDriverTimeoutException was unhandled
  HResult=-2146233088
  Message=Timed out after 10 seconds
  Source=WebDriver.Support
  StackTrace:
       at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
       at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
       at SeleniumTest.Program.Main(String[] args) in C:\Users\justin.oconnor\OneDrive\Visual Studio\Projects\SeleniumTest\SeleniumTest\Program.cs:line 28
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233088
       Message=Unable to find element on closed window
       Source=WebDriver
       StackTrace:
            at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
            at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
            at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
            at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
       InnerException: 

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c83cc490-a34e-43dd-92e6-86528d7cd075%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Selenium WebDriver Not Finding Elements

Selenium - Users mailing list
Did you ever find a solution for this issue? Having the same issue on my end:
"OpenQA.Selenium.WebDriverTimeoutException was unhandled by user code; Message=Timed out after 5 seconds; Source=WebDriver.Support;"

The code I am attempting with:

   Private Sub WaitForLoad(ByRef driver As PhantomJSDriver, ByVal Timeout As TimeSpan, ByVal FindField As IWebElement)
        Try
            Dim wait As WebDriverWait = New WebDriverWait(driver, Timeout)
            wait.Until(ExpectedConditions.ElementToBeClickable(FindField))
        Catch ex As OpenQA.Selenium.WebDriverTimeoutException
            MessageBox.Show("1")
            Throw New Exception(ex.Message)
        Catch ex As WebDriverException
            MessageBox.Show("2")
            Throw New Exception(ex.Message)
        Catch ex As System.TimeoutException
            MessageBox.Show("3")
            Throw New Exception(ex.Message)
        Catch ex As Exception
            MessageBox.Show("4")
            Throw New Exception(ex.Message)
        End Try
    End Sub


On Saturday, 9 April 2016 05:41:04 UTC+1, Justin O'Connor wrote:
I started having issues with Selenium being able to detect elements on a page.  Up until yesterday this code worked just fine, but something seems to have changed causing the WebDriver to timeout versus finding the Element.  I tried modifying the code to point to <a href="http://google.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://google.com&#39;;return true;" onclick="this.href=&#39;http://google.com&#39;;return true;">google.com and <a href="http://bing.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fbing.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGoyDTY0Ct4snf3iz9zM8mJ_yeiVQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fbing.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGoyDTY0Ct4snf3iz9zM8mJ_yeiVQ&#39;;return true;">bing.com and search for the Name("q"), but it's not picking it up.

I'm using Internet Explorer 11 for this.  Has anyone else come across this before?
It's worth noting that I rolled back to the previous drivers in case an updated driver caused the problems (even though there hasn't been one published since last month), but the results remain the same.

I set the timeout for 10 seconds to give the page a chance to fully load, otherwise I would throw an exception.

namespace SeleniumTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var _ieOptions = new InternetExplorerOptions();
            _ieOptions.IgnoreZoomLevel = true;
            var _driver = new InternetExplorerDriver(_ieOptions);
            //var __driver = new ChromeDriver();

            var _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
            _driver.Navigate().GoToUrl("<a href="http://172.16.3.163:163/Execute/Display" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2F172.16.3.163%3A163%2FExecute%2FDisplay\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHSkgASb5Etqg1FzXtvpEr8qNh-Tw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2F172.16.3.163%3A163%2FExecute%2FDisplay\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHSkgASb5Etqg1FzXtvpEr8qNh-Tw&#39;;return true;">http://172.16.3.163:163/Execute/Display");


            _wait.Until(ExpectedConditions.ElementExists(By.Name("UserId")));
            _driver.FindElement(By.Name("UserId")).SendKeys("Google");
                   
        }
    }
}




Here's the error.
OpenQA.Selenium.WebDriverTimeoutException was unhandled
  HResult=-2146233088
  Message=Timed out after 10 seconds
  Source=WebDriver.Support
  StackTrace:
       at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
       at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
       at SeleniumTest.Program.Main(String[] args) in C:\Users\justin.oconnor\OneDrive\Visual Studio\Projects\SeleniumTest\SeleniumTest\Program.cs:line 28
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233088
       Message=Unable to find element on closed window
       Source=WebDriver
       StackTrace:
            at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
            at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
            at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
            at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
       InnerException: 

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9b796f97-02f3-44d4-894c-7a7094e060af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...