0

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.

1 Answer 1

2

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.

3
  • Honestly, I still have no idea how to do it. Can you explain more details, please? In C#, please.
    – Majkl
    Commented Jun 4, 2019 at 18:30
  • I have changed the code to c#. This code should expand the "Field" list from your screenshots.
    – Moro
    Commented Jun 5, 2019 at 11:06
  • This solution works as expected. Thank you very much.
    – Majkl
    Commented Jun 5, 2019 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.