Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

c# - Loop behaving like nested loops when iterating through ReadOnlyCollection<AppiumWebElement>

I encountered an issue while trying to check all the checkboxes in a windows application

This is my code:

Actions actions = new Actions(driver);

var elements = driver.FindElementByName("Upload Categories").FindElementsByTagName("CheckBox");
        
foreach (var element in elements)
{
    actions.DoubleClick(element).Perform();
}

And I would expect the code to iterate through all the elements and double click on them.

Instead it behaves like there is another loop inside iterating a list of elements made out of the required element and all the elements indexed before it in the initial list.

I don't understand why

LE:

It had something to do with the fact that "actions" is declared outside of the loop

This is the working version:

var elements = driver.FindElementByName("Upload Categories").FindElementsByTagName("CheckBox");
        
foreach (var element in elements)
{
    Actions actions = new Actions(driver);
    actions.DoubleClick(element).Perform();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...