How to use Selenium in Excel VBA to wait for a specific value to appear

Having an element with the following HTML:

<span id="ContentPlaceHolder1_Label2" designtimedragdrop="1319" style="display:inline-block;color:Firebrick;font-size:Medium;font-weight:bold;width:510px;"></span>

Upon clicking the Save button on the page, this part changes to:

<span id="ContentPlaceHolder1_Label2" designtimedragdrop="1319" style="display:inline-block;color:Firebrick;font-size:Medium;font-weight:bold;width:510px;">Successfully saved changes</span>

You will notice the value Successfully saved changes. The issue arises when the internet connection is slow as the other button gets clicked before saving. How can I make sure to wait for the appearance of the text Successfully saved changes before proceeding to click the other button?

Thank you in advance for any assistance.

Answer №1

This particular method was put to the test by me and it performed admirably. All credit goes to Ziggus for providing the necessary guidance.

Do Until .FindElementById("ContentPlaceHolder1_Label2").Text = "تم حفظ التعديل بنجاح"
    Application.Wait Now() + TimeValue("00:00:01")
Loop

Answer №2

Here is my revised version of the code to prevent an infinite loop by adding a timed loop and including DoEvents.

Dim output As String, element As Object, time As Date
Const MAX_WAIT_TIME As Long = 10 '<==adjust time here
time = Timer
Do
    DoEvents
    On Error Resume Next
    Set element = .FindElementById("ContentPlaceHolder1_Label2")
    output = element.Text
    If Timer - time > MAX_WAIT_TIME Then Exit Do
    On Error GoTo 0
Loop While output <> "تم حفظ التعديل بنجاح"

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

Selenium Server operates in a manner distinct from WebDriver

I'm experiencing some challenges with Selenium. Let me try to outline the setup I have and what I am attempting to accomplish. Summarized Version: My automated tests run smoothly locally using a Ruby webdriver gem. However, when I run the same scrip ...

Unable to find the element on the Google Chrome web page

I'm currently working on changing the name of my Chrome profile using Python and Selenium. The specific location I need to modify can be found at chrome://settings/manageProfile. The element I am trying to access is an empty textbox located in the to ...

Selenium - Element not located using xpath

Searching for a particular element in this webpage, specifically the bid price in the initial row: 196.20p. Utilizing selenium, here is the code I am using: from selenium import webdriver driver = webdriver.PhantomJS() address = 'https://www.trustne ...

Utilize clipboard functionality in automated tests while using Selenium WebDriver in conjunction with JavaScript

How can I allow clipboard permission popups in automated tests using Selenium web driver, Javascript, and grunt? https://i.stack.imgur.com/rvIag.png The --enable-clipboard and --enable-clipboard-features arguments in the code below do not seem to have an ...

Selenium in Python failing to check the checkbox

Why am I encountering difficulty in selecting the checkbox on the webpage using Selenium with Python? import traceback import selenium.webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as ...

Guide on capturing a screenshot with consistent window size using Selenium in Python

I'm running into an issue where I want to capture a screenshot in headless mode using Selenium at a specific resolution, but the saved image is turning out to be at a different resolution despite setting the window size: from selenium import webdriver ...

Utilizing the same WebDriverJS instance repeatedly

As a beginner in Selenium, I successfully launched a website using the following Node.js code snippet: var webdriver = require('selenium-webdriver'); var driver = new webdriver.Builder() .forBrowser('chrome') .build(); console ...

What are the best practices for managing certificates with Selenium?

I am currently utilizing Selenium to initiate a browser. What is the best approach for handling webpages (URLs) that prompt the browser to accept or deny a certificate? In the case of Firefox, I sometimes encounter websites that require me to accept their ...

waiting for elements in Nightwatch.js using FluentWait

I am seeking assistance on implementing FluentWait using nightwatch.js. How can I achieve this? Within my project, I have a global.js file that includes: waitForConditionPollInterval : 300, waitForConditionTimeout : 5000, However, it seems like this ...

Verify that the option is present in the dropdown menu

My dropdown menu contains a list of subjects. To retrieve the values from the dropdown, I used the following code snippet: IList<IWebElement> allOptions = check.Options; Next, I created an array of strings to hold the subject names that I need to ...

Check whether an element is currently in focus with Selenium WebDriver

It's surprising that there doesn't seem to be much information available online about testing for element focus using Selenium Webdriver. I'm interested in verifying that when a form is submitted without filling in a mandatory field, the fo ...

Steps for retrieving the attribute values of <i> tags enclosed within a designated <div> element

Currently, I am extracting data from a website where I encounter a recurring pattern with a varying number of values. For example, an instance of this pattern is shown below: <div class="lang"> <i class="flag fr" qtip-tooltip= ...

Working with multiple dropdowns dynamically in VBA and utilizing either webelements or selectelements

Recently, I have been working with Selenium and VBA and encountering an issue. When trying to work with dynamic drop-downs, I am unable to refresh my web element or select element and sometimes receive error messages. For instance, I am dealing with a web ...

Scrapy spider malfunctioning when trying to crawl the homepage

I'm currently using a scrapy scrawler I wrote to collect data from from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor from scrapy.selector import Selector from .. import items clas ...

Having trouble with Selenium 2.51 WebDriver C# unable to launch Firefox on Windows 7 X64?

While I have successfully managed to launch Firefox on Selenium v2.0.50727 using C# .net3.5, I face issues when trying to load Firefox on Selenium 2.5.1 as it tends to hang (in both C# .net3.5/net.4). Unfortunately, there are no error logs available to p ...

Determining when the scroll bar has reached the end using Selenium in Python

I'm working on implementing a while loop in Selenium, and I want to set a condition for the loop to stop when the scroll bar reaches the end of the page. How would I go about coding this type of condition within the while loop? Right now, my loop is s ...

The Selenium test case script using JUnit is malfunctioning on Eclipse when attempting to run it with the Firefox driver

I have attempted to run my program using various versions of Firefox (45, 48, 49, and 50) with no success. I have also specified the path for the Gecko driver (64 bit) within my code, but unfortunately, the Firefox browser fails to open when I execute the ...

Selenium/c# facing issue with clicking Dynamics365 dropdown menu - getting "ElementNotVisibleException" error

Currently working on automating Dynamics365 CRM using Selenium/C#. I am able to successfully click and drop down the menu, however, I am facing issues finding and clicking on the "Submitted" option (line 2 of the code). The exception I am encountering is: ...

Python's selenium code appears to halt at the click function, even though the button has been successfully clicked

After clicking the button, the code stops and does not continue. print("I'm going to click on the toaster") site.find_element(By.XPATH,"//div[text()='Click to view']").click() print("The toaster was clicked") When Python clicks the button, ...

Occasionally experiencing timeout exceptions with Webdriver. The HTTP request to the remote WebDriver server for a specific URL is causing intermittent issues

My tests started failing randomly across IE and Firefox from today. All the failures are showing me this exception. Earlier, I was using VS2013, with Nunit version 3.0.1, IEDriver 2.45.0.0, Selenium.Support and Selenium.WebDriver 2.48.2. I initially though ...