Guide to sending keystrokes to a web browser using Selenium and VBA

Recently, I created a straightforward piece of code to log into Gmail using Excel VBA. Here's what it looks like:

 Sub signInToGmail()
Dim bot As New WebDriver
Dim i As Integer
bot.Start "chrome", ""

bot.Wait 3000
bot.FindElementById("form-username").SendKeys ("my email")
bot.Wait 3000
bot.FindElementById("form-password").SendKeys ("my password")
bot.Wait 3000
bot.FindElementById("login-btn").Click
bot.Wait 2000

End Sub

This method functions correctly. However, each time the code is executed, a new browser window opens, and any previous browsing history is lost. Additionally, the user must enter their login credentials every time.

As an alternative approach, I modified the code as follows:

Sub automatedLogin()

Dim browser As New WebDriver
Dim i As Integer
  Dim chromePath As String

  chromePath = """C:\Program Files\Google\Chrome\Application\chrome.exe"""


 browser.Wait 3000
    browser.FindElementById("form-username").SendKeys ("my mail")
    browser.Wait 3000
    browser.FindElementById("form-password").SendKeys ("my password")
    browser.Wait 3000
    browser.FindElementById("login-btn").Click
    browser.Wait 2000
    

End Sub

With this updated code, Chrome opens with saved login information. However, there seems to be an issue with sending keys using this method, resulting in an error message being displayed (see image below). Any advice on how to resolve this would be greatly appreciated. Thank you.

[enter image description here] 1

Answer №1

Here's a code snippet that I frequently use in my scripts to locate the extension path for Chrome. It should look something like this -

"USER_Libin\\AppData\\Local\\Google\\Chrome\\Extensions\\tracker\\1.9"

Firstly, create a variable to store the path and then implement the following patch:

Sub Demo_Test()
    Dim driver As New ChromeDriver

    With driver
        .AddArgument “–-load-extension=” + pathToExtension

Let me know if you have success with this method!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty uploading an image with Selenium in Java

Looking for a reliable way to upload images using Selenium Web driver with Java? Here are some methods I've tried: sendkeys() : Unfortunately, this method isn't working for me (xpath used: //input[@id='brandingContent_AddImage']) Robot ...

The script functions properly when in debug mode, but does not run when switching to run mode in the IE browser

I have attempted running the following code in both Firefox and IE. It seems to be working fine in Firefox, however, I am experiencing issues in IE. I am using IE v11, Selenium v2.45, and have also tried versions 2.46 and 2.44. I am also utilizing IE Dri ...

Is there a potential security measure that can deactivate automation processes?

I'm currently developing a Python script using the Selenium Chrome Webdriver to automate tasks on this specific Swedish website: . My main focus is automating the login process, however I have encountered some persistent errors such as: selenium.comm ...

"Troubleshoot: Resolving Issues with Opening URLs in Selenium from a

I am encountering an issue while trying to open URLs from a TXT file using the Selenium WebDriver. The code I am using is written in Python 3.4.3. Could you help me identify the problem in this code? from selenium import webdriver with ope ...

Unable to locate the addEventListener function when utilizing php webdriver and selenium

I have been working with the webdriver for just three weeks now, and I've come across an issue regarding finding addEventListener. My setup includes using the selenium standalone server in combination with a PHP framework developed by Facebook. My g ...

The functionality of mouse hover is malfunctioning on IE11 and Firefox

When attempting to mouse hover on a particular element using the Action class in Selenium and then move to another sub-element to click, the mouse cursor ends up pointing elsewhere. These are the Internet Explorer capabilities that have been configured al ...

Attempting to utilize the default Chrome profile in Selenium with Ruby for testing purposes

At the moment, my Cucumber testing involves using Selenium with Ruby. I came across an issue where the chrome tab created during testing does not have the same settings as my regular browsing Chrome tab. This is a problem because I rely on an extension i ...

Efficient Rotation with AWS Proxy in Conjunction with Amazon API Gateway and Selenium

Looking to scrape websites using selenium. Successfully implemented selenium on ec2, but since ec2 is tied to a specific IP, I'm interested in incorporating Amazon API Gateway rotating proxy into my python selenium script. Came across this helpful t ...

What could be the reason why my TestNG xml file is not directing to my Java Class?

Why isn't my TestNG XML file able to locate my Runner Class? This is how my XML File looks like: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Cucumber Framework" verbo ...

Tips on selecting an element with xpath in Selenium WebDriver (It usually does the trick, but not working on this particular URL)

Attempting to access an input field on the website by utilizing xpath. Normally, this method works for all URLs, but for this specific one, I am unable to click on the input field using selenium webdriver. The webdriver successfully loads the page but fai ...

Executing Python scripts from a shared directory

Can individuals without Python installed run a Python Selenium script as long as all dependencies are available in a shared directory? For example, if the entire Python folder and its libraries are placed in a shared directory, would users be able to exec ...

Automate button clicking on web pages using Python with Selenium

While I am able to access the tag below through css_selector, I am unsure how to perform a button click. <a title="Sign In" onclick="toggleLogin('signInBlock','regBenefitsBlock');" href="javascript:void(0);">Sign In</a> I ...

Is there a way to extract the text from a textarea using webdriver?

When attempting to retrieve the contents of a textarea within an HTML form using webdriver in Python, I am able to get the text, but the newlines are missing. Despite consulting the selenium docs, which provide limited information: class selenium.webdrive ...

What is the correct method for downloading an Excel file in a Vue.js application?

I am having difficulty downloading an Excel file in xlsx format using my Vue.js application. The Vue.js application sends a post request to the Node.js application which then downloads the Excel file from a remote SFTP server. The backend application is fu ...

Connecting to Selenium Server with Mink: A Step-by-Step Guide

Currently attempting to set up Behat tests with a selenium server. This is my behat.yml configuration: default: paths: features: features bootstrap: %behat.paths.features%/bootstrap extensions: Behat\MinkExtension\Extension: bas ...

How can you traverse through CSS page numbers using Python?

Is there a way to create a loop that iterates through page numbers for aria-label? browser.find_element_by_css_selector('[aria-label="Page 1"').click() browser.find_element_by_css_selector('[aria-label="Page 2"').cli ...

determining the position of the substring located within an "if any" function

I have two lists A and B. My goal is to extract a string from list A, find a matching string in list B, and then determine the index of that matching string in list B. I've attempted several nested loops without success. I haven't come across an ...

selenium.common.exceptions.InvalidArgumentException: Message: The argument provided is not valid: 'name' must be a string when transitioning between window handles using Selenium

Whenever I try to use the following code snippet: driver.execute_script("window.open('');") driver.switch_to.window(driver.window_handles[1]) driver.get(url) driver.switch_to.window(driver.window_handles[0]) An error is thrown at me. s ...

What can be done to continue execution even after assertion failures occur?

When using Selenium WebDriver with Java and TestNG for automation, I encounter situations where there are multiple assertions within a test method. If one of these assertions fails, the execution is halted. My goal is to have the code continue executing e ...

Check for the presence of incorrect information to verify its visibility

My current task involves writing a test in Selenium where I have designated all my web elements in a page object package. To access the web element in my test, I am utilizing S.getColumn(). The getcolumn() function retrieves the web element of the column ...