Click here to Skip to main content
15,611,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

IList<IWebElement> labels = driver.FindElements(By.ClassName(textBox1.Text));
            textBox2.Text = labels.ToString();

as the output of this code
in the Listbox1

in the textbox2

I'm getting these results
I can't get data from the site

What I have tried:

String labels = driver.FindElement(By.ClassName(textBox1.Text)).Text;

one by one data craw, I get correct results, but not as a list
Updated 23-Feb-21 22:23pm

1 solution

The variable labels is an IList (Collection) of items. So calling labels.ToString() will correctly tell you that is is a Collection object. If you want to view the individual items then you need to iterate the collection with some type of for/foreach loop.
Share this answer
CL4Y3R-TR 24-Feb-21 4:48am    
I tried to add it to the list but it didn't work
Richard MacCutchan 24-Feb-21 5:03am    
You cannot add a collection of items in that way. As I already explained you need to use a for/foreach loop to iterate the collection. Alternatively you could use a BindingSource. If you do not understand how classes and collections work then check the documentation for the classes you are using.
CL4Y3R-TR 24-Feb-21 5:13am    
IList<IWebElement> all = driver.FindElements(By.ClassName(textBox1.Text));

            String[] allText = new String[all.Count];
            int i = 0;
            foreach (IWebElement element in all)
                allText[i++] = element.Text;

i tried this not worked
Richard MacCutchan 24-Feb-21 5:21am    
What is the purpose of the string array when you do not keep it, and you are not passing the element.Text property to the ListBox.Items? All you need to do is:
foreach (IWebElement element in all)

And if it still does not show any results, then you need to step through the code with your debugger to see what is in the list.
CL4Y3R-TR 24-Feb-21 5:29am    
Thank u Soo much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900