florentbr/SeleniumBasic

How to change the user agent profile of edge in VBA(Selenium)

tariqfaiyaz opened this issue · 1 comments

I have the below code to access a site and get to another page, but I need the code to set the user agent profile of the edge instance to "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4501.0 Safari/537.36 Edg/91.0.866.0" before it accesses the site.

I haven't been able to find a way to do this in VBA. any thoughts??

Sub idash_test()
    
    Set cd = New Selenium.EdgeDriver
    Dim ls As Selenium.SelectElement
    Dim rp As Selenium.SelectElement
    

    
    cd.Start "edge"
    cd.Get "http://idash.uhc.com/#/"
    Set ls = cd.FindElementByCss("#sel_viewas_001492341").AsSelect
    ls.SelectByValue "000791032"
    cd.FindElementByLinkText("Reports").Click
    Application.Wait (Now + TimeValue("00:00:10"))
    cd.FindElementByXPath("/html/body/div[2]/div/span/nav/ul/li[1]/a").Click
    Application.Wait (Now + TimeValue("00:00:10"))
    cd.FindElementByXPath("/html/body/div[2]/div/span/nav/ul/li[1]/ul/li[2]/a").Click
    Application.Wait (Now + TimeValue("00:00:10"))
    cd.FindElementByXPath("/html/body/div[2]/div/span/nav/ul/li[1]/ul/li[2]/ul/li[1]/a").Click
    Application.Wait (Now + TimeValue("00:00:10"))

End Sub

Try this. It works for Chrome

`Set drv = New Selenium.ChromeDriver

drv.SetPreference "general.useragent.override", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4501.0 Safari/537.36 Edg/91.0.866.0"`