GCuser99 / SeleniumVBA

A comprehensive Selenium wrapper for browser automation developed for MS Office VBA running in Windows
MIT License
89 stars 18 forks source link

chrome://flags : forgotten arrow #63

Closed surfer-silver closed 1 year ago

surfer-silver commented 1 year ago

wondering why chrome is not able to get correct location and found that not using windows location api if need to use we have to set experimental feature through flags and found following option to be through a function in Selenium https://www.selenium.dev/selenium/docs/api/dotnet/?topic=html/T_OpenQA_Selenium_Chrome_ChromeOptions.htm ChromeOptions.AddLocalStatePreference Method WebDriver Adds a preference for the local state file in the user's data directory for Chrome. If the specified preference already exists, it will be overwritten.

i am damn sure you will definitely add this to SeleniumVBA to get more control over chrome and for those who want location services from such websites https://www.gps-coordinates.net/my-location https://whatmylocation.com/

GCuser99 commented 1 year ago

@surfer-silver, I'm not sure I understand what you are asking for above - maybe you can demonstrate with some code? I think the WebCapabilities class should allow you to add any preference that you want to so maybe you can suggest a usage case to make your thinking clearer?

BTW, I just added GetGeolocation and SetGeolocation methods (Edge and Chrome only) to the WebDriver class that will allow you to do the following:

Sub test_geolocation()
    Dim driver As WebDriver

    Set driver = New WebDriver

    driver.StartChrome 'Chrome and Edge only
    driver.OpenBrowser

    'set the location lat and lon
    driver.SetGeolocation 41.1621429, -8.6219537

    driver.NavigateTo "https://www.gps-coordinates.net/my-location"
    driver.Wait 1000

    'print the name/address of the location to immediate window
    Debug.Print driver.FindElementByXPath("//*[@id='addr']").GetText

    driver.CloseBrowser
    driver.Shutdown
End Sub
GCuser99 commented 1 year ago

@surfer-silver, I finally figured out what the "forgotten arrow" was... I added a new method in WebCapabilities class to make it easier:

Here is what you had to do before:

Dim localStatePrefs As New Dictionary
localStatePrefs.Add "browser.enabled_labs_experiments", Array("download-bubble@2", "download-bubble-v2@2")
caps.SetOption "localState", localStatePrefs
driver.OpenBrowser caps

Here is what you can do with v4.7:

caps.AddLocalStateFlags "download-bubble@2", "download-bubble-v2@2"
driver.OpenBrowser caps