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
1 Answer 1
Replace this:
var values = mySelect.SelectedOption;
With this:
var values = mySelect.Options;
That way your foreach
loop will work, because you'll have a list of options to loop through. Your current code only returns a single element, on which foreach
does not work.
-
when i changed to var values = mySelect.Otions; get error message Error 1 'OpenQA.Selenium.Support.UI.SelectElement' does not contain a definition for 'Otions' and no extension method 'Otions' accepting a first argument of type 'OpenQA.Selenium.Support.UI.SelectElement' could be found (are you missing a using directive or an assembly reference?) C:\Users\Numg\Desktop\selenium\ConsoleApplication5\ConsoleApplication5\Program.cs 53 39 ConsoleApplication5Daniel Shmayovich– Daniel Shmayovich2017年04月01日 12:22:05 +00:00Commented Apr 1, 2017 at 12:22
-
Really you didnt notice the spelling error? and the missing p... lolNiels van Reijmersdal– Niels van Reijmersdal2017年04月01日 12:24:03 +00:00Commented Apr 1, 2017 at 12:24
-
sorry my bud,but now i get error message Test Name: ADDITEMTOCART Test Outcome: Failed Result Message: System.InvalidOperationException : unknown error: Element <a class="button delete-share" data-id="delete-0">...</a> is not clickable at point (921, 539). Other element would receive the click: <span>...</span> (Session info: chrome=56.0.2924.87) (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64) Result StandardOutput: opened url close the broswerDaniel Shmayovich– Daniel Shmayovich2017年04月01日 17:15:05 +00:00Commented Apr 1, 2017 at 17:15
Explore related questions
See similar questions with these tags.