mistake within the do while loop

public Login ClickGetStatus()
{
    //IWebElement btnGetStatus = driver.FindElement(By.XPath("//*[contains(@id,'GetStatus')]"));
    do
    {
        buttonName_GetStatus[0] = "abc";
        Thread.Sleep(3000);

        bool is_displayed = 
            wrapper.IsElementDisplayed(
                driver.FindElement(By.XPath("//*[contains(@id,'GetStatus')]")));

        //bool IsElementDisplayed = driver.FindElement(By.XPath("//*[contains(@id,'GetStatus')]")).Displayed;


        if (is_displayed)
        {
            //wrapper.Click(btnExecute);

            string getnameofbutton1 = 
                driver.FindElement(
                    By.XPath("//*[contains(@id,'GetStatus')]")).GetAttribute("id");

            Console.WriteLine("Name of the button is : " + getnameofbutton1);

            buttonName_GetStatus = getnameofbutton1.Split('_');
            driver.FindElement(
                By.XPath("//*[contains(@id,'GetStatus')]")).Click();
        }
        else
        {
            Console.WriteLine("Element is not displayed");
        }
    }
    while (buttonName_GetStatus[0] == "GetStatus");

    return this;
}

This script handles the functionality to click on the "Get Status" button as described below:

  • The script looks for a button with the ID containing "Get Status"
  • If it finds the "Get Status" button, it clicks on it
  • Xpath uses 'contains' due to dynamically changing IDs
  • However, the issue arises when the button name changes to "View Result" but the script still searches for "Get Status", causing an infinite loop

Answer №1

If you are expecting the ID of the button to change to "ViewResult" after an update, then it is recommended to modify the condition accordingly.

while (buttonName_GetStatus[0] != "ViewResult");

This loop will continue running until the button's ID is equal to "ViewResult".

Does this align with the intended functionality you are aiming for?

public Login ClickGetStatus()
{
    //IWebElement btnGetStatus = driver.FindElement(By.XPath("//*
    [contains(@id,'GetStatus')]"));
    do
    {
    buttonName_GetStatus[0] = "abc";
    Thread.Sleep(3000);

    var elements = driver.FindElements(By.XPath("//*[contains(@id,'GetStatus')]"));

    var is_displayed = elements.Count > 0;

    //bool IsElementDisplayed = driver.FindElement(By.XPath("//*[contains(@id,'GetStatus')]")).Displayed;


    if (is_displayed)
    {
        //wrapper.Click(btnExecute);

        string getnameofbutton1 = 
            driver.FindElement(
                By.XPath("//*[contains(@id,'GetStatus')]")).GetAttribute("id");

        Console.WriteLine("Name of the button is : " + getnameofbutton1);

        buttonName_GetStatus = getnameofbutton1.Split('_');
        driver.FindElement(
            By.XPath("//*[contains(@id,'GetStatus')]")).Click();
    }
    else
    {
        Console.WriteLine("Element is not displayed");
    }
}
while (buttonName_GetStatus[0] != "ViewResult");

return this;
}

Answer №2

Upon closer examination, it seems that the issue lies here. Specifically, when verifying if isDisplayed is equal to true, the subsequent line

buttonName_GetStatus = getnameofbutton1.Split('_');
ends up overwriting the array, resulting in an infinite loop.

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

Is there a way to establish a default class name with Selenium WebDriver when dealing with two panels that share the same class name

The task at hand involves scrolling through panels in my system, where two panels exist with scrollbars that share the same Class name. I am using Selenium Webdriver and need assistance on how to specifically scroll down the second panel. Scrollbar Class ...

Determining the accessibility and availability of a webdriver (utilizing selenium grid) instance

While reviewing my test logs, I came across the following error: WebDriverException: Session [id] was terminated due to FORWARDING_TO_NODE_FAILED. I am currently using webdriver with a grid configuration that has the HUB located in Boston and the node in ...

Using Selenium to interact with a hidden button under a span element

I am seeking to automate the process of selecting an environment on a screen where there are multiple individual buttons hidden within spans, displayed as tiles. While I have been able to successfully navigate to a specific tile and reveal the button, I a ...

What could be causing the issue with receiving deserialized data in my WebAPI?

I have a straightforward WebAPI application. Here is an excerpt from my controller: [HttpPost] public ActionResult DoSomeWork(string stringParam, DTOObject dto) { // Some work happens here } My console application is calling this method as follows: ...

Disappearing ASP control conundrum: The curious case of ajax (Telerik)

I'm having an issue with my asp button "btn" and label "lbl". When I click the button, the text in the label is supposed to change but instead it disappears. Here's what my aspx file looks like: <form id="form1" runat="server"> <tel ...

Guidelines for running Selenium scripts on a pre-existing browser in Mac OS

//cd /Applications //Google\ Chrome.app --remote-debugging-port=6655 --user-data-dir=/Users/admin/Documents/chromedata Strange issue with terminal commands: When trying to enter the above commands, an error is received stating that Google Chrome.app ...

Guide to uploading a file in a pop-up window using Selenium remote WebDriver on a Linux system

Currently, I am faced with the task of automating an application on a Windows machine. Upon clicking a specific button, a window popup is triggered which allows me to either select a file or input a path. The upload functionality is operational using the ...

How does the import statement determine which files to import from?

Transitioning my Eclipse setup from one computer to another has been a bit challenging. I specialize in working with Selenium, so after transferring my workspaces, importing projects, and adding the necessary jars, I'm still encountering numerous erro ...

The program cannot locate the reference to the 'NUnit' type or namespace

Recently, I encountered an issue with a c# code that was exported from Selenium IDE. using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using Selenium; namespace SeleniumTests { [TestFixt ...

Struggling to locate the Twitter direct message input box with Xpath in Selenium

I have been struggling to locate the textbox element using the find_element_by_xpath() method. Unfortunately, every time I try it, I receive an error stating that the element cannot be found. Here is the specific line of code in question: Despite attempti ...

Execute the unsuccessful Selenium Nunit tests again

We have observed that in our testing environment, some tests fail intermittently under certain conditions. Therefore, my query is how can we specifically rerun the Nunit tests that have failed? One approach I am considering is to include steps in the Nun ...

Tips for resolving SQLite cookie error code 1555 in Python when using Selenium

I have a piece of code that is designed to open a specific website, log in, and then go to a directed link. It was working perfectly when I tested it individually, but now I need to run multiple instances of it. To achieve this, I simply copy and paste the ...

Tips for uploading files to Microsoft Edge using Selenium

I've been working on uploading files to a website using Selenium and encountered an issue specifically with Microsoft Edge. The code I'm using works perfectly in Firefox, Chrome, and Safari, but for some reason, it fails when running against Edg ...

Selenium test using JUnit experiencing failure due to driver prematurely accessing URL

My goal is to make sure this particular test passes. I am verifying if the webpage URL matches the expected URL. The problem lies in the fact that the driver captures the URL before the next page fully loads, resulting in it comparing the old URL with the ...

Steps to convert a JSON property into an attribute of an XML element

I'm trying to use Newtonsoft's .Net Library to convert JSON to XML, but I'm wondering if there is a way to convert a specific JSON element to an XML attribute? For instance, let's say we have the following JSON: { "array": { ...

Is it possible to retrieve ZIP codes from a website using Selenium with Python?

Just starting out with Python Selenium and looking to extract some specific information. I need to pull the postal code 10080 from this link: tools.keycdn.com/geo ...

Verifying a tooltip value for a specific section (bar) on a bar chart using Selenium WebDriver

Is there a way to extract the value 31732 from the margin (sum) tooltip for Electrolux vendor in the bar chart shown below? https://i.stack.imgur.com/CIgIW.png The following HTML provides the code for the div enclosing this value. Your advice on how to ...

Tips for utilizing AjaxElementLocatorFactory with Selenium and Page Factory

When setting up my pages in Selenium, I have utilized Pagefactory to handle the elements. However, I am facing an issue with dynamic tests where certain elements only exist in some tests. My understanding is that AjaxElementFactory functions as follows: P ...

Try out the latest feature in Selenium IDE - switching to an iframe using the frame

I am currently facing an issue with selecting an element within an Iframe using Selenium IDE. The tool seems to be unable to identify the desired element. open | https://verify-taxcerts.floridarevenue.com pause | | 30000 select frame | id=ivuFrm_page0ivu3 ...

Issues with Selenium's waitForElementPresent method causing delays in the execution of test scripts

I have been conducting tests on a website using Selenium Grid with recordings from Selenium Builder. So far, everything is working fine for Firefox and Chrome on both Windows and Mac operating systems. However, I am encountering errors when testing on Wind ...