I was recently doing some automation of a web procedure and ran into a problem that I had to go round and round to solve.
Initially I started by recording the interaction with the Selenium IDE and everything worked correctly in the test browser. The problem came when trying to move it to another browser and the web page required the browser to share the location.
By default all browsers block these requests and we have to give access individually to each domain. This is done with the classic modal request window like the following:
Once we have accepted it the browser will save that permission and the site will work correctly.
The problem is that when performing an automation with Selenium we don't necessarily start from a browser with a certain configuration. Therefore we will have to add this configuration in the tests so that it always works correctly.
The solution I am going to show is for Firefox and the tests are written in Python. In the creation of the webdriver we will have to pass a set of options that will become the preferences of the browser instance.
def setup_method(self, method):options = Options()options.set_preference('geo.enabled, True)options.set_preference('geo.prompt. testing.prompt.testing.allow.allow, True)options.set_preference('geo.prompt.testing.allow.allow, True)options.set_preference('permissions.default.geo.default.geo, True)options.set_preference('geo.provider.network. url, 'data:applicationJson,{"location: {"latelink: 40.7590, "lng: -73.9845}, "accuracy: 27000.0})self.driver = webdriver. Firefox(options=options)
In the JSON payload of the geo.provider.network.url field, we can modify the values of longitude, latitude and precision to the ones we are interested in for our case.
It is important to note that this method only works on recent versions of Firefox because the names of some preferences have changed.
Also note that this system is fully compatible with launching tests remotely in Selenium Grid.
Comments1
¡Hola! Es un placer…
¡Hola! Es un placer saludarte. Quería escribirte porque creo que Mariogalan tiene una gran oportunidad de aparecer en prensa como noticia real y destacarse en los principales periódicos digitales con publicaciones de alto impacto.
Aquí te detallo los beneficios de esta propuesta:
* Aparición garantizada: Publicación asegurada en más de 40 periódicos digitales de gran autoridad.
* Artículos reales: No se marcan como publicidad y nunca se borran, potenciando el posicionamiento de tu web en los primeros lugares de internet.
* Contenido que impulsa tu marca: Perfecto para compartir en tu web y redes sociales, mejorando tu reputación online.
* Política de devolución: Si no se publica, te devolvemos el dinero.
Por menos de 100e, puedes obtener un impacto mediático valorado en más de 7.000e. Incluso, me encantaría ofrecerte un mes gratuito para que pruebes los resultados en tu negocio.
Puedes confirmarme un número de teléfono o reservar una llamada desde el siguiente enlace: https://calendly.com/aparecer-prensa/15min
Saludos,