0

Please see the HTML code below

<div class="dgrid-content ui-widget-content" tabindex="0">

<div id="uniqName-36397" class=" dgrid default Item001">
<div id="uniqName-36780" class=" dgrid default Item003">
Pankaj Dubey
  • 279
  • 2
  • 18

1 Answers1

0

Use XPath. You can try:

"//div[starts-with(@id, 'uniqName-')]"

This will fetch all the elements whose id attribute value begins with uniqName-.

You can iterate over each element by using the following code:

IList<IWebElement> elements = driver.FindElements(By.XPath("//div[starts-with(@id, 'uniqName-')]"));
foreach(IWebElement element in elements) {
    //Do Something
}
JRodDynamite
  • 12,325
  • 5
  • 43
  • 63
  • Thanks for your answer Jason, but it will return all elements where ID starts with 'UniqName..' but how to go on my corresponding ID to perform the action. lets say that there are 10 elements on page where ID starts with 'UniqName..' – Pankaj Dubey Dec 04 '15 at 06:10
  • @PankajDubey - You can iterate over it. If you want a specific `id` value then you can use `By.Id`. – JRodDynamite Dec 04 '15 at 06:28