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.

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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