Skip to main content

C# selenium web driverSelenium WebDriver Foreach not working

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But

But just every time the values inside the dropdown are changed:

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
var mySelect = new SelectElement(mySelectElm);
var values = mySelect.SelectedOption;
foreach (var option in values)
{
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
 }

thatThat the error I get but I need help with writing the code better:

Error 1

foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator'

C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

C# selenium web driver Foreach not working

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
var mySelect = new SelectElement(mySelectElm);
var values = mySelect.SelectedOption;
foreach (var option in values)
{
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
 }

that the error I get but I need help with writing the code better:

Error 1

foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator'

C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

C# Selenium WebDriver Foreach not working

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete.

But just every time the values inside the dropdown are changed:

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
var mySelect = new SelectElement(mySelectElm);
var values = mySelect.SelectedOption;
foreach (var option in values)
{
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
 }

That the error I get but I need help with writing the code better:

Error 1

foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator'

C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
   new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

 PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
 var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
 var mySelect = new SelectElement(mySelectElm);
 var values = mySelect.SelectedOption;
 foreach (var option in values)
 {
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
  }

that the error iI get but iI need help with writing the code better

Error 1:

`foreach` statement cannot operate on variables of type `'OpenQA.Selenium.IWebElement'` because `'OpenQA.Selenium.IWebElement'` does not contain a public definition for 'GetEnumerator'    

    C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs   54  17  ConsoleApplication5

Error 1

foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator'

C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
   new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

 PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
 var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
 var mySelect = new SelectElement(mySelectElm);
 var values = mySelect.SelectedOption;
 foreach (var option in values)
 {
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
  }

that the error i get but i need help with writing the code better

Error 1

`foreach` statement cannot operate on variables of type `'OpenQA.Selenium.IWebElement'` because `'OpenQA.Selenium.IWebElement'` does not contain a public definition for 'GetEnumerator'    

    C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs   54  17  ConsoleApplication5

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
var mySelect = new SelectElement(mySelectElm);
var values = mySelect.SelectedOption;
foreach (var option in values)
{
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
 }

that the error I get but I need help with writing the code better:

Error 1

foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator'

C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

thisThis is my code in c #C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

           PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
            new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
            PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

  PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
            var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
            var mySelect = new SelectElement(mySelectElm);
            var values = mySelect.SelectedOption;
            foreach (var option in values)
            {
                Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
                PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
            }

that the error i get but i need help with writewriting the code better Error

Error 1 foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator' C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

`foreach` statement cannot operate on variables of type `'OpenQA.Selenium.IWebElement'` because `'OpenQA.Selenium.IWebElement'` does not contain a public definition for 'GetEnumerator'    

    C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs   54  17  ConsoleApplication5

this is my code in c # I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

           PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
            new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
            PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

  PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
            var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
            var mySelect = new SelectElement(mySelectElm);
            var values = mySelect.SelectedOption;
            foreach (var option in values)
            {
                Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
                PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
            }

that the error i get but i need help with write the code better Error 1 foreach statement cannot operate on variables of type 'OpenQA.Selenium.IWebElement' because 'OpenQA.Selenium.IWebElement' does not contain a public definition for 'GetEnumerator' C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 54 17 ConsoleApplication5

This is my code in C# I press the delete button and open a pop up where I select the amount of deletions that I want to delete and press again on delete it will delete.

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
   new SelectElement(PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"))).SelectByText("1");
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();

What I'm trying to do is record a loop every time I press delete and open a pop-up window, find the highest value inside the dropdown and select it and delete. But just every time the values inside the dropdown are changed

 PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click();
 var mySelectElm = PropertiesCollections.driver.FindElement(By.XPath("(//select[@id='remove_shares'])[2]"));
 var mySelect = new SelectElement(mySelectElm);
 var values = mySelect.SelectedOption;
 foreach (var option in values)
 {
    Console.WriteLine(option.Text); //Prints "Option", followed by "Not Option"
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
  }

that the error i get but i need help with writing the code better

Error 1

`foreach` statement cannot operate on variables of type `'OpenQA.Selenium.IWebElement'` because `'OpenQA.Selenium.IWebElement'` does not contain a public definition for 'GetEnumerator'    

    C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs   54  17  ConsoleApplication5
Source Link
Loading