GPS location
unknown
ruby
3 years ago
1.6 kB
4
Indexable
require 'rubygems' require 'appium_lib' caps = { 'bstack:options' => { "osVersion" => "11.0", "deviceName" => "Google Pixel 4", "local" => "false", } } caps['browserstack.gpsLocation'] = '21.166015055568003, 72.84003145657289' appium_driver = Appium::Driver.new({'caps' => caps,'appium_lib' => { :server_url => "http://<username>:<access_key>@hub-k8s-devautomate2.bsstag.com/wd/hub" }}, true) driver = appium_driver.start_driver # WebCam Test driver.navigate.to "https://html5demos.com/geo/" sleep(2) # To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button. driver.set_context('NATIVE_APP') driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click; # driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click; sleep(5) driver.set_context('CHROMIUM') # wait = Selenium::WebDriver::Wait.new(timeout: 10) # Click the "Show my location" button button = wait.until { driver.find_element(id: 'button') } button.click # Wait for the latitude and longitude elements to be displayed wait.until { driver.find_element(id: 'latitude') } wait.until { driver.find_element(id: 'longitude') } # Get the latitude and longitude elements latitude_element = driver.find_element(id: 'latitude') longitude_element = driver.find_element(id: 'longitude') # Get the text content of the latitude and longitude elements latitude = latitude_element.text longitude = longitude_element.text # Print the latitude and longitude puts "Latitude: #{latitude}" puts "Longitude: #{longitude}" sleep(2) driver.quit
Editor is loading...