### Home Classes Methods

### In Files

- jobbie/src/rb/lib/selenium/webdriver/ie/util.rb

### Methods

- #create_element
- #create_element_collection
- #create_string
- #extract_elements_from
- #extract_string_from
- #string_array_from
- #wstring_ptr
- #wstring_to_bytestring

### Class/Module Index

Quicksearch

- Selenium
- Selenium::WebDriver
- Selenium::WebDriver::BridgeHelper
- Selenium::WebDriver::ChildProcess
- Selenium::WebDriver::ChildProcess::IronRubyProcess
- Selenium::WebDriver::ChildProcess::JRubyProcess
- Selenium::WebDriver::ChildProcess::WindowsProcess
- Selenium::WebDriver::Chrome
- Selenium::WebDriver::Chrome::Bridge
- Selenium::WebDriver::Chrome::CommandExecutor
- Selenium::WebDriver::Chrome::Launcher
- Selenium::WebDriver::Chrome::Launcher::MacOSXLauncher
- Selenium::WebDriver::Chrome::Launcher::UnixLauncher
- Selenium::WebDriver::Chrome::Launcher::WindowsLauncher
- Selenium::WebDriver::Driver
- Selenium::WebDriver::DriverExtensions
- Selenium::WebDriver::DriverExtensions::TakesScreenshot
- Selenium::WebDriver::Element
- Selenium::WebDriver::Error
- Selenium::WebDriver::Error::ElementNotDisplayedError
- Selenium::WebDriver::Error::ElementNotEnabledError
- Selenium::WebDriver::Error::ElementNotSelectableError
- Selenium::WebDriver::Error::ExpectedError
- Selenium::WebDriver::Error::IndexOutOfBoundsError
- Selenium::WebDriver::Error::InvalidCookieDomainError
- Selenium::WebDriver::Error::NoCollectionError
- Selenium::WebDriver::Error::NoScriptResultError
- Selenium::WebDriver::Error::NoStringError
- Selenium::WebDriver::Error::NoStringLengthError
- Selenium::WebDriver::Error::NoStringWrapperError
- Selenium::WebDriver::Error::NoSuchCollectionError
- Selenium::WebDriver::Error::NoSuchDocumentError
- Selenium::WebDriver::Error::NoSuchDriverError
- Selenium::WebDriver::Error::NoSuchElementError
- Selenium::WebDriver::Error::NoSuchFrameError
- Selenium::WebDriver::Error::NoSuchWindowError
- Selenium::WebDriver::Error::NullPointerError
- Selenium::WebDriver::Error::ObsoleteElementError
- Selenium::WebDriver::Error::ServerError
- Selenium::WebDriver::Error::TimeOutError
- Selenium::WebDriver::Error::UnableToSetCookieError
- Selenium::WebDriver::Error::UnexpectedJavascriptError
- Selenium::WebDriver::Error::UnhandledError
- Selenium::WebDriver::Error::UnknownCommandError
- Selenium::WebDriver::Error::UnknownScriptResultError
- Selenium::WebDriver::Error::UnsupportedOperationError
- Selenium::WebDriver::Error::WebDriverError
- Selenium::WebDriver::FileReaper
- Selenium::WebDriver::Find
- Selenium::WebDriver::Firefox
- Selenium::WebDriver::Firefox::Binary
- Selenium::WebDriver::Firefox::Bridge
- Selenium::WebDriver::Firefox::Launcher
- Selenium::WebDriver::Firefox::Profile
- Selenium::WebDriver::Firefox::ProfilesIni
- Selenium::WebDriver::Firefox::Util
- Selenium::WebDriver::IE
- Selenium::WebDriver::IE::Bridge
- Selenium::WebDriver::IE::Kernel32
- Selenium::WebDriver::IE::Lib
- Selenium::WebDriver::IE::Util
- Selenium::WebDriver::Keys
- Selenium::WebDriver::Navigation
- Selenium::WebDriver::Options
- Selenium::WebDriver::Platform
- Selenium::WebDriver::Remote
- Selenium::WebDriver::Remote::Bridge
- Selenium::WebDriver::Remote::Capabilities
- Selenium::WebDriver::Remote::Http
- Selenium::WebDriver::Remote::Http::Common
- Selenium::WebDriver::Remote::Http::Curb
- Selenium::WebDriver::Remote::Http::Default
- Selenium::WebDriver::Remote::Response
- Selenium::WebDriver::TargetLocator
- Selenium::WebDriver::Timeouts
- Dir
- SocketError
- String

No matching classes.

# Selenium::WebDriver::IE::Util

@private

### Constants

CP_ACP
CP_MACCP
CP_OEMCP
CP_SYMBOL
CP_THREAD_ACP
CP_UTF7
CP_UTF8

### Public Instance Methods

create_element(&blk) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 46
    def create_element(&blk)
      element_ptr_ref = FFI::MemoryPointer.new :pointer
      yield element_ptr_ref
      Element.new(self, element_ptr_ref.get_pointer(0))
    ensure
      element_ptr_ref.free
    end

create_element_collection(&blk) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 54
    def create_element_collection(&blk)
      elements_ptr_ref = FFI::MemoryPointer.new :pointer
      yield elements_ptr_ref

      extract_elements_from elements_ptr_ref
    end

create_string(&blk) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 61
    def create_string(&blk)
      wrapper = FFI::MemoryPointer.new :pointer
      yield wrapper

      extract_string_from wrapper
    end

extract_elements_from(elements_ptr_ref) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 91
    def extract_elements_from(elements_ptr_ref)
      elements_ptr = elements_ptr_ref.get_pointer(0)
      length_ptr   = FFI::MemoryPointer.new :int

      check_error_code Lib.wdcGetElementCollectionLength(elements_ptr, length_ptr),
                       "Cannot extract elements from collection"

      arr = []

      length_ptr.get_int(0).times do |idx|
        arr << create_element do |ptr|
          result = Lib.wdcGetElementAtIndex(elements_ptr, idx, ptr)

          if e = WebDriver::Error.for_code(result)
            Lib.wdFreeElementCollection(elements_ptr, 1)
            raise e, "unable to create element from collection at index #{idx} (#{result})"
          end
        end
      end

      Lib.wdFreeElementCollection(elements_ptr, 0)

      arr
    ensure
      elements_ptr_ref.free
      length_ptr.free
    end

extract_string_from(string_ptr_ref) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 68
    def extract_string_from(string_ptr_ref)
      string_ptr = string_ptr_ref.get_pointer(0)
      return if string_ptr.null? # getElementAttribute()

      length_ptr = FFI::MemoryPointer.new :int

      if Lib.wdStringLength(string_ptr, length_ptr) != 0
        raise Error::WebDriverError, "cannot determine length of string"
      end

      length     = length_ptr.get_int(0)
      raw_string = wstring_ptr(" "*length)

      if Lib.wdCopyString(string_ptr, length, raw_string) != 0
        raise Error::WebDriverError, "cannot copy string from native data to Ruby string"
      end

      wstring_to_bytestring raw_string
    ensure
      Lib.wdFreeString(string_ptr) unless string_ptr.null?
      string_ptr_ref.free
    end

string_array_from(raw_strings) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 18
    def string_array_from(raw_strings)
      strings_ptr = raw_strings.get_pointer(0)
      length_ptr  = FFI::MemoryPointer.new :int
      result      = Lib.wdcGetStringCollectionLength(strings_ptr, length_ptr)

      if result != 0
        raise Error::WebDriverError, "cannot extract strings from collection, error code: #{result.inspect}"
      end

      arr    = []

      length_ptr.get_int(0).times do |idx|
        str_ptr_ref = FFI::MemoryPointer.new :pointer
        result = Lib.wdcGetStringAtIndex(strings_ptr, idx, str_ptr_ref)

        if result != 0
          raise Error::WebDriverError, "unable to get string at index: #{idx}, error: #{result}"
        end

        arr << extract_string_from(str_ptr_ref)
      end

      arr
    ensure
      Lib.wdFreeStringCollection(strings_ptr)
      raw_strings.free
    end

wstring_ptr(str) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 120
    def wstring_ptr(str)
      str  = str.to_s
      size = Kernel32.MultiByteToWideChar(CP_UTF8, 0, str, -1, nil, 0)

      unless size > 0
        raise Error::WebDriverError, "unable to convert #{str.inspect} to wchar ptr"
      end

      buf = FFI::MemoryPointer.new :pointer, size
      Kernel32.MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, size)

      buf
    end

wstring_to_bytestring(wstring) click to toggle source

    # File jobbie/src/rb/lib/selenium/webdriver/ie/util.rb, line 134
    def wstring_to_bytestring(wstring)
      size = Kernel32.WideCharToMultiByte(CP_UTF8, 0, wstring, -1, nil, 0, nil, nil)

      unless size > 0
        raise Error::WebDriverError, "could not convert wstring pointer to bytestring"
      end

      buf = FFI::MemoryPointer.new :pointer, size
      Kernel32.WideCharToMultiByte(CP_UTF8, 0, wstring, -1, buf, size, nil, nil )

      buf.get_bytes(0, size - 1)
    ensure
      buf.free if buf
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.