Selenium WebDriver Not Finding Elements

瀏覽次數:400 次
跳到第一則未讀訊息

Justin O'Connor

未讀,
2016年4月9日 凌晨12:41:042016/4/9
收件者:Selenium Users
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: 

Chris W

未讀,
2017年6月1日 晚上11:24:102017/6/1
收件者:Selenium Users
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
回覆所有人
回覆作者
轉寄
0 則新訊息