How to click a expand button if ID is randomly generated



  • I have a problem how to click a desired expand button if ID is randomly generated. This means that the ID has another value after refresh page. Of course, the ID has another value for each row. I don't know how to click on expand button for 1st Field, 1st Operator, 2nd Field....etc. Here is a code for a first row, 1st Field button:

    enter image description here

    Here is a code for a first row, 1st Operator button:

    enter image description here

    Here is a code for a second row, 1st Field button:

    enter image description here

    Thanks in advance for your help.



  • You need to capture a List of elements. Then the first row will be the first element of the list and so on. Your html structure makes it quite simple, so for the field elements it would be:

    IList<IWebElement> fields = driver.FindElements(By.CssSelector("table[id='advFilter'] td[class='field'] div[class='apidrop apidicon']"));
    fields[0].Click();
    

    The selector used here is looking into the table with id=advFilter, then looks for a td element with class=field, then for the button - which is located inside a div with a class=apidrop apidicon.

    For other elements you need to change the td classname.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2