First, the answer below will not be that elegant if you are testing a complex web app. If you really want to do the ExtJS ui testing right, add class names to relevant elements. If you can't get developers to do so, life will be miserable.
Step 1: find the window by cssSelector .x-window
or xpath //*[contains(@class, 'x-window')]
Step 2: find all checkboxes, cssSelector input[id^='checkboxfield']
or xpath //input[starts-with(@id, 'checkboxfield')]
. Alternatively, you may also find table[id^='checkboxfield']
first, then get the input
inside, but logic is the same.
Step 3: index the one you want
List<IWebElement> checkboxes = driver.findElements(By.cssSelector(".x-window input[id^='checkboxfield']"));
//checkboxes.size() here should be six in your case?
checkboxes[0].click();
I'd suggest you to learn how to use xpath or cssSelector effectively. However, the reason I think this answer is still not elegant is because indexing a list of elements is not a stable approach.
Whenever UI changes, your tests fail. If you have a custom class name for that checkbox, it will be much easier, as you can locate this particular checkbox by its unique class name (e.g checkbox-owner-write
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…