Automating Firefox using Selenium and VBA

2,658 views
Skip to first unread message

thomas alexander lawford granger

unread,
May 22, 2018, 5:55:43 PM5/22/18
to Selenium Users
Hi,

I've well versed in VBA programming and I've now tried moving into Firefox automation with little success. I've been trying for several months now to automate Firefox through selenium.

I am using: 
- MS Office Professional Plus 2010 
- Firefox 34.0.5 (I read Selenium doesn't work with higher versions of FF)
- Selenium IDE 2.4.0
- Selenium Wrapper 1.0.17.0
- Selenium Basic 2.0.9.0

I have recorded the following code in selenium IDE, outputted it to VBA script; however whenever I try running the code in VBA It trips up and stalls. 
___________________________________________________________________________
  Dim driver As New SeleniumWrapper.WebDriver
  Dim By As New By, Assert As New Assert, Verify As New Verify, Waiter As New Waiter
  driver.Start "firefox", "https://www.ebay.co.uk/"
  driver.setImplicitWait 5000

  driver.Get "/"
  driver.FindElementByLinkText("Sign in").Click
  driver.FindElementById("2031759456").Clear
  driver.FindElementById("2031759456").SendKeys USERNAME
  driver.FindElementById("707377953").Clear
  driver.FindElementById("707377953").SendKeys PASSWORD
  driver.FindElementById("sgnBt").Click
  driver.FindElementById("941057401").Clear
  driver.FindElementById("941057401").SendKeys PASSWORD
  driver.FindElementById("sgnBt").Click
  
  driver.stop
___________________________________________________________________________

I can't break out of the code and after a timeout period I get a message "Microsoft Excel is waiting for another application to complete an OLE action". I have to forcefully close Excel in task manager.

I've been trying a load of different things with no success. Can someone please help me?

David

unread,
May 25, 2018, 12:01:51 AM5/25/18
to Selenium Users
If you're versed in VBA (which is also VB, VBscript), why not try this alternative if the Selenium VBA binding is giving you issues: http://htejera.users.sourceforge.net/vbswebdriver/

thomas alexander lawford granger

unread,
Jun 5, 2018, 5:18:25 PM6/5/18
to Selenium Users
Hi David,

So I tried the link and I didn't get much further. I've downloaded the VBScript webdriver and it's just a handful of vbscript files. 

I know the programming language however I don't quite understand what I'm supposed to do with this. Would you be able to provide a bit more information into what I'm supposed to do next?

Sorry for my incompetence! This isn't something I'm familiar with.

Thanks
Tom

Nilton da Silva

unread,
Jun 5, 2018, 10:43:49 PM6/5/18
to seleniu...@googlegroups.com
Enter the developer tab, look for the tools tab and click References and see if this is enabled the selenium wrapper. I think that might be it.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/cc4add2f-610f-4ea3-9d36-15efd8e657aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

thomas alexander lawford granger

unread,
Jun 6, 2018, 5:56:10 PM6/6/18
to Selenium Users
Hi Nilton,

Thank you for your message. If you're talking about the references in the tools tab of the vba editor then I have already enabled:

- SeleniumWrapper Type Library
- Selenium Type Library

Do I need anything else?

Thanks,
Tom

David

unread,
Jun 6, 2018, 8:57:17 PM6/6/18
to Selenium Users
For the VBScript webdriver, if you can call VBScript from VBA in Excel or Office apps, you can probably used it. I'd need to set up a demo myself sometime. You just need a way to "import" the code (like a library) to be able to call it in VBA, with the hacky way by copying & pasting the code into your VBA project. I think I recall long time back there's a method in VBScript (and thus VBA?) to read/load VB code into memory from file, which is equivalent of modern day library imports, and have used that before, don't have the exact info with me though.

Something like this: https://icodealot.com/dynamic-methods-in-vbscript/, if you can do similar in VBA, you can import the VBScript webdriver to then create an instance of it to work with.

Nilton da Silva

unread,
Jun 6, 2018, 9:31:54 PM6/6/18
to seleniu...@googlegroups.com
Eu acho que você está tentando criar uma maneira de logar no site, então eu coloquei para fazer isso, testá-lo e ver se funciona. Você precisa habilitar a Biblioteca de tipos de selênio para que funcione no menu Ferramentas na guia Referências




Dim driver como o Webdriver

Sub David ()

Definir driver = Novo ChromeDriver

Application.Wait Now + TimeValue ("00:00:01")

driver.FindElementByLinkText ("Login"). Clique em
  driver.FindElementByXPath (".//*[@ id = 'userid']"). SendKeys ("UserName")
  
  
 driver.FindElementByXPath (".//*[@ id = 'pass']"). SendKeys ("Senha")
  driver.FindElementById ("sgnBt"). Clique em


  
   
  driver.Quit
  
  
End Sub


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

thomas alexander lawford granger

unread,
Jun 10, 2018, 8:11:09 AM6/10/18
to Selenium Users
Hi David,

Thank you for your reply. I've had a go with VBScript and I think I could do it with a bit of work, however I'm trying to keep everything within VBA. There are a few variable waiting periods and if the VBA code resumes for the VBScript has completed this could cause problems. I think it's adding additional complications into something that's already quite complex.

If you can provide any assistance with getting VBA to talk to Firefox that'd be fantastic!

Thanks,
Tom

thomas alexander lawford granger

unread,
Jun 10, 2018, 12:48:01 PM6/10/18
to Selenium Users
Hi Nilton,

Your way is working, with a little tweaking. The code I recorded through selenium IDE doesn't work with VBA. it doesn't like the initial declaration of "Dim driver As New SeleniumWrapper.WebDriver"

So now I've got Firefox responding to VBA; however Firefox isn't loading up with the default profile. I use a proxy server with firefox so it's important Firefox opens with my settings. When Firefox opens it's a blank new user and it doesn't have my proxy settings.

I've tried setting the profile in VBA using the following code:

driver.SetProfile ("C:\Users\Tom\AppData\Local\Mozilla\Firefox\Profiles\a9itx68r.default")
driver.get "https://www.ebay.co.uk/", Raise = False

It ignores the profile and opens without any of the proxy setting etc.

Can you help here?

Thanks,
Tom
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Nilton da Silva

unread,
Jul 10, 2018, 8:37:27 AM7/10/18
to Selenium Users
Olá, Tom, esse procedimento que usei usa selênio básico em vez de selênio. Quanto às configurações, como ele abre um navegador controlado pelas configurações do webdriver não estão presentes. Eu não sei se existe como configurado pelo vba. Instale o selênio básico usando este link https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0
Para usar, não esqueça de ir para a guia developer / tools / references e selecionar Selenium Type Library.

Em domingo, 10 de junho de 2018 13:48:01 UTC-3, thomas alexander lawford granger escreveu:
Hi Nilton,

Seu caminho está funcionando, com um pouco de ajustes. O código que gravei através do selenium IDE não funciona com o VBA. não gosta da declaração inicial de "Dim driver As New SeleniumWrapper.WebDriver"

Então agora eu tenho o Firefox respondendo ao VBA; no entanto, o Firefox não está carregando com o perfil padrão. Eu uso um servidor proxy com o Firefox por isso é importante o Firefox abre com minhas configurações. Quando o Firefox abre é um novo usuário em branco e não tem minhas configurações de proxy.

Eu tentei definir o perfil no VBA usando o seguinte código:

Driver.SetProfile ("C: \ Usuários \ Tom \ AppData \ Local \ Mozilla \ Firefox \ Perfis \ a9itx68r.default")
driver.get " https://www.ebay.co.uk/ ", aumento = falso

Ele ignora o perfil e abre sem qualquer configuração de proxy, etc.

Você pode ajudar aqui?

Obrigado,
Tom

On Thursday, 7 June 2018 02:31:54 UTC+1, Nilton da Silva wrote:
Eu acho que você está tentando criar uma maneira de logar no site, então eu coloquei para fazer isso, testá-lo e ver se funciona. Você precisa habilitar a Biblioteca de tipos de selênio para que funcione no menu Ferramentas na guia Referências




Dim driver como o Webdriver

Sub David ()

Definir driver = Novo ChromeDriver

Application.Wait Now + TimeValue ("00:00:01")

driver.FindElementByLinkText ("Login"). Clique em
  driver.FindElementByXPath (".//*[@ id = 'userid']"). SendKeys ("UserName")
  
  
 driver.FindElementByXPath (".//*[@ id = 'pass']"). SendKeys ("Senha")
  driver.FindElementById ("sgnBt"). Clique em


  
   
  driver.Quit
  
  
End Sub

2018-06-06 21:57 GMT-03:00 David <mang...@gmail.com>:
Para o webbdriver VBScript, se você puder chamar o VBScript a partir do VBA em aplicativos do Excel ou do Office, provavelmente poderá usá-lo. Eu precisaria criar uma demonstração em algum momento. Você só precisa de uma maneira de "importar" o código (como uma biblioteca) para poder chamá-lo em VBA, com o modo hacky, copiando e colando o código em seu projeto VBA. Eu acho que há muito tempo atrás, há um método no VBScript (e, portanto, VBA?) Para ler / carregar o código VB na memória do arquivo, que é equivalente às importações da biblioteca moderna, e usei isso antes, não tenho a exata info comigo embora.

Algo como isto:  https://icodealot.com/ dynamic-methods-in-vbscript / , se você pode fazer semelhante em VBA, você pode importar o webbdriver VBScript para criar uma instância dele para trabalhar.

Na terça-feira, 5 de junho de 2018 às 14:18:25 UTC-7, thomas alexander lawford granger escreveu:
Olá David,

Então tentei o link e não fui muito além. Eu fiz o download do webdriver VBScript e é apenas um punhado de arquivos vbscript. 

Eu conheço a linguagem de programação, mas não consigo entender o que devo fazer com isso. Você seria capaz de fornecer um pouco mais de informação sobre o que eu deveria fazer a seguir?

Desculpe pela minha incompetência! Isso não é algo que eu esteja familiarizado.

obrigado
Tom

-
Você recebeu esta mensagem porque está inscrito no grupo "Usuários do Selenium" dos Grupos do Google.
Para cancelar a inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para selenium-user ... @ googlegroups. com .
Para enviar mensagens para este grupo, envie um e-mail para seleniu ... @ googlegroups.com .
Para ver esta discussão na Web, visite https://groups.google.com/d/ msgid / selenium-users / e62c9792- f398-43a6-afaa-449adf03f349% 40googlegroups.com .

Para obter mais opções, visite https://groups.google.com/d/ optout .

Reply all
Reply to author
Forward
0 new messages