Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find multiple elements on a page in selenium?

Tags:

c#

selenium

I have multiple input HTML tags on same page having same id and name or class,

Now How should I find 2nd or 3rd.. etc input. I can work with arrays so Do we have some function which will return all the textBox(input tag) from that page.

like image 741
Mudit Singh Avatar asked Oct 21 '25 20:10

Mudit Singh


1 Answers

First you create a list with FindElements, then you can iterate through that list. For example:

var allTextBoxes = driver.FindElements(By.TagName("input"));

foreach(var textBox in allTextBoxes)
{
    textBox.DoSomething();
}

You can use a for-loop as well:

for(int i = 0; i < allTextBoxes.Count; i++)
{
   allTextBoxes[i].DoSomething();
}     

Or if you want a specific Element, in example the 3rd:

allTextBoxes[2].DoSomething();
like image 101
Anaxi Avatar answered Oct 23 '25 10:10

Anaxi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!