Dashboard > Watir > ... > Simple Examples > Browser and OS Versions
Watir Log In View a printable version of the current page.
Browser and OS Versions
Added by Paul Rogers, last edited by Alister Scott on Sep 29, 2008  (view change) show comment
Labels: 
(None)

Something like the following code can be used to get the browser version and OS version. I'll probably extend this to work with Firefox and other OS

class IE
	
    # returns the browser version
	# based on http://blogs.msdn.com/ie/archive/2006/09/20/763891.aspx
	# and http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/aboutuseragent.asp
	def browser_version
		n = self.document.invoke('parentWindow').navigator.appVersion
		if m=n.match(/MSIE\s(.*?);/)
		    return m[1]
		end
		return ""
	end
	
	# this method gets the os version from the browsers useragent string
	# based on http://blogs.msdn.com/ie/archive/2006/09/20/763891.aspx
	# and http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/aboutuseragent.asp
	def os_version
		b = self.document.invoke('parentWindow').navigator.appVersion
		if n=b.match(/Windows NT(.*?);/)
		    if n[1].strip == "5.1"
		        return "Windows XP"
		    elsif n[1].strip == "5.2"    
		        return "Windows 2003 Server"
		    elsif n[1].strip == "6.0"
		        return "Vista"
		    else
		        return ""        
		    end    
		end
		return ""


	end
	
end

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators