lib/watir/ie-class.rb in watir-1.6.7 vs lib/watir/ie-class.rb in watir-1.7.0.rc1
- old
+ new
@@ -48,12 +48,11 @@
$HIDE_IE = nil
@@visible = x
end
# Used internally to determine when IE has finished loading a page
- READYSTATE_INTERACTIVE = 3
- READYSTATE_COMPLETE = 4
+ READYSTATES = {:complete => 4}
# The default color for highlighting objects as they are accessed.
HIGHLIGHT_COLOR = 'yellow'
# IE inserts some element whose tagName is empty and just acts as block level element
@@ -310,11 +309,10 @@
end
attr_writer :hwnd
# Are we attached to an open browser?
def exists?
- return false if @closing
begin
@ie.name =~ /Internet Explorer/
rescue WIN32OLERuntimeError
false
end
@@ -394,11 +392,10 @@
end
# Closes the Browser
def close
return unless exists?
- @closing = true
@ie.stop
wait rescue nil
chwnd = @ie.hwnd.to_i
@ie.quit
while Win32API.new("user32","IsWindow", 'L', 'L').Call(chwnd) == 1
@@ -485,11 +482,11 @@
begin
while @ie.busy
sleep interval
end
- until [READYSTATE_INTERACTIVE, READYSTATE_COMPLETE].include?(@ie.readyState)
+ until READYSTATES.has_value?(@ie.readyState)
sleep interval
end
until @ie.document
sleep interval
@@ -501,11 +498,11 @@
return @down_load_time
end
while doc = documents_to_wait_for.shift
begin
- until ["interactive", "complete"].include?(doc.readyState)
+ until READYSTATES.has_key?(doc.readyState.to_sym)
sleep interval
end
@url_list << doc.location.href unless @url_list.include?(doc.location.href)
doc.frames.length.times do |n|
begin
@@ -890,9 +887,22 @@
puts e.to_s
end
return htmlString
end
private :html_source
+
+ # execute css selector and return an array of (ole object) elements
+ def elements_by_css(selector)
+ xmlparser_document_object # Needed to ensure Nokogiri has been loaded
+ xpath = Nokogiri::CSS.xpath_for(selector)[0]
+ elements_by_xpath(xpath)
+ end
+
+ # return the first (ole object) element that matches the css selector
+ def element_by_css(selector)
+ temp = elements_by_css(selector)
+ return temp[0] if temp
+ end
# return the first element that matches the xpath
def element_by_xpath(xpath)
temp = elements_by_xpath(xpath)
temp = temp[0] if temp