The geolocation in HTML5

Source: Internet
Author: User

In HTML5, the new feature geolocation is used to locate user location information.

Because the user location information is sensitive information, you need to be allowed by the user before the program can get the current user information through the API. Each time the Webdriver program is re-allowed to be a new session process, the user's location information has been accessed manually by the browser in a timely manner, but the previous user settings are still not available in the current running environment. The workaround is to let the browser execute the Webdriver test program every time, and the user settings will still be loaded.

In Firefox, for example, on a Mac OS platform, you can open the user Profile Manager with the following command

$/applications/firefox.app/contents/macos/firefox-bin-profilemanager

Other platform Open Way query official developer Documentation:

Https://developer.mozilla.org/en-US/docs/Mozilla/Multiple_Firefox_Profiles

After creating the Geolocation profile successfully, click Start Firefox to start Firefox browser.

Take http://www.weschools.com/html/html5_geolocation.asp as an example. To demonstrate the complete sample code, you also need to create a JSON file containing geolocation information, named Location.json, which reads as follows:

{

"Status": "OK",

"Accuracy": 10.0,

"Location": {"lat": 52.1771129, "LNG": 5.4}

}

Example:

Package COM.LEARNINGSELENIUM.HTML5;

Import Org.openqa.selenium.By;

Import Org.openqa.selenium.WebDriver;

Import Org.openqa.selenium.firefox.FirefoxDriver;

Import Org.openqa.selenium.firefox.FirefoxProfile;

Import Org.openqa.selenium.firefox.internal.Profileslni;

Import org.testng.annotations.*;

public class testhtml5geolocation{

private static Webdriver driver;

@BeforeClass

public void SetUp () throws exception{

Get geolocation profile

Firefoxprofile profile = new Profileslni (). GetProfile ("geolocation");

Configuring geolocation Information

Profile.setpreference ("Geo.wifi.uri", "/selenium 2/mydoc/codes/4/location.json");

Launch Browser via custom profile

Driver = new Firefoxdriver (profile);

Driver.get ("http://www.weschools.com/html/html5_geolocation.asp");

}

@Test

public void Testgetlocation () throws exception{

Driver.findelement (By.cssselector ("P#demo button"). Click ();

}

@AfterClass

public void TearDown () throws exception{

Driver.quit ();

}

}

The geolocation in HTML5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.