Skip to content

Instantly share code, notes, and snippets.

@feelobot
Created November 4, 2013 21:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feelobot/7309729 to your computer and use it in GitHub Desktop.
Save feelobot/7309729 to your computer and use it in GitHub Desktop.
Troubleshooting Webview with Ruby:

Once this is included in your project you can use

Helper.find_web_element("div#ad_banner")

If if does not work then the element does not exist. I am sure the code can be cleaned up but this is how I managed to solve my issues with hybrid app testing.

DEFAULT_WAIT = 60
class Helper
def self.find_web_element(css)
handles = $driver.window_handles
$driver.manage.timeouts.implicit_wait = 5
handles.each do |window|
$driver.switch_to.window(window)
begin
el = $driver.find_element(:css,css)
if el
return el
else
return false
end
rescue
end
end
$driver.execute_script("mobile: leaveWebView")
$driver.manage.timeouts.implicit_wait = DEFAULT_WAIT
end
def self.find_web_elements(css)
handles = $driver.window_handles
$driver.manage.timeouts.implicit_wait = 5
handles.each do |window|
$driver.switch_to.window(window)
begin
els = $driver.find_elements(:css,css)
return els if els.length > 0
rescue
end
end
$driver.execute_script("mobile: leaveWebView")
$driver.manage.timeouts.implicit_wait = DEFAULT_WAIT
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment