Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetPageSource sometimes throws ElementNotAvailableException #6

Closed
NickAb opened this issue Jun 3, 2015 · 1 comment
Closed

GetPageSource sometimes throws ElementNotAvailableException #6

NickAb opened this issue Jun 3, 2015 · 1 comment

Comments

@NickAb
Copy link
Contributor

NickAb commented Jun 3, 2015

Some times GetPageSource method throws ElementNotAvailableException

ERROR: test_click_button (__main__.TestApp2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:/Users/*/Desktop/fbautomation.py", line 158, in test_click_button
    print(self.driver.page_source)
  File "C:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 438, in page_source
    return self.execute(Command.GET_PAGE_SOURCE)['value']
  File "C:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 175, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 136, in check_response
    raise exception_class(value)
WebDriverException: Message: System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.Runtime.InteropServices.COMException: Operation timed out. (Exception from HRESULT: 0x80131505)

   at UIAutomationClient.IUIAutomationElement.FindAllBuildCache(TreeScope scope, IUIAutomationCondition condition, IUIAutomationCacheRequest cacheRequest)

   at System.Windows.Automation.AutomationElement.FindAll(TreeScope scope, Condition condition)

   --- End of inner exception stack trace ---

   at System.Windows.Automation.AutomationElement.FindAll(TreeScope scope, Condition condition)

   at Winium.StoreApps.CodedUITestProject.WiniumElement.GetChildrens()

   at Winium.StoreApps.CodedUITestProject.WiniumElement.AsXml()

   at Winium.StoreApps.CodedUITestProject.CommandExecutors.GetPageSourceExecutor.DoImpl()

   at Winium.StoreApps.CodedUITestProject.CommandExecutors.CommandExecutorBase.Do()

@NickAb
Copy link
Contributor Author

NickAb commented Jun 7, 2015

Both FindAll and FindFirst are prone to this exception, which is raised when trying to find elements in WebView that has loaded its data recently, exception is thrown when methods try to build cache, so it might be due to trying to iterate visual tree while it is being rebuild by another thread.

Replacing FindAll with

private IEnumerable<WiniumElement> GetChildrens()
        {
            var elementNode = TreeWalker.ControlViewWalker.GetFirstChild(this.AutomationElement);

            while (elementNode != null)
            {
                yield return new WiniumElement(elementNode);
                elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
            }
        }

Solves the problem. Needs further investigation. Most likely we will have to replace both FindFirst and FindAll calls with custom TreeWalker iteration method.

This will solve the problem with not being able to get page source for views with webviews and not being able to find element in webview due to same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant