Skip to content

Instantly share code, notes, and snippets.

@feelobot

feelobot/Readme.md

Created Nov 4, 2013
Embed
What would you like to do?
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