WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Is there any way to click on all elements returned from a FindElements list?

Open ycoliveira opened this issue 8 years ago • 5 comments

In my App I have a view where I have to evaluate itens, so there is a lot of "Yes" and "No" pictureBoxes. Is there any to use something like FindElementsByAccessibilityId("picBoxYes") and Click() on all returned elements from this collection?

ycoliveira avatar Feb 21 '18 17:02 ycoliveira

Can't you use a foreach loop on the returned results? So e.g.: var foundResults = FindElementsByAccessibilityId("picBoxYes"); foreach(var element in foundResults) { element.Click(); }

OR, depending on how you're calling WAP, you might be able to cut out the variable declaration entirely (e.g. if you're using a page object pattern and have the FindElements call abstracted out into a method or property):

foreach(var element in SomeWindowObject.FindAllYesBoxes) { element.Click(); }

PandaMagnus avatar Feb 22 '18 20:02 PandaMagnus

I've tried this code but It didn't work:

var foundResults = Driver.Session.FindElementsByAccessibilityId("picBoxYes");
 foreach(var element in foundResults)
{
     element.Click();
}

That's how I clicking on the buttons:

Driver.Session.FindElementByAccessibilityId("Consi").FindElementByAccessibilityId("picBoxYes").Click();
Driver.Session.FindElementByAccessibilityId("Consi").FindElementByAccessibilityId("picBoxYes").Click();
Driver.Session.FindElementByAccessibilityId("SOMETHING").FindElementByAccessibilityId("picBoxYes").Click();

Since I have this structure repeatedly, I want to know if I can use something like

Driver.FindElementsByAccessibilityId("PicBoxYes");

Then use a loop structure to click on every PicBoxYes element on my screen;

My xml has this structure repeatedly, changing just the first AutomationId:

<Pane AcceleratorKey="" AccessKey="" AutomationId="Consi" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533352" x="1526" y="2878" width="355" height="125">
	<Pane AcceleratorKey="" AccessKey="" AutomationId="tlpMain" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533266" x="1526" y="2878" width="355" height="125">
		<Pane AcceleratorKey="" AccessKey="" AutomationId="pnlTitle" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533366" x="1541" y="2878" width="325" height="25">
			<Text AcceleratorKey="" AccessKey="" AutomationId="lblTitleItem" ClassName="WindowsForms10.STATIC.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="False" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="text" Name="Consi" Orientation="None" ProcessId="7700" RuntimeId="42.533262" x="1541" y="2878" width="288" height="20" />
			</Pane>
			<Pane AcceleratorKey="" AccessKey="" AutomationId="pnlComentario" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="selecionado" Orientation="None" ProcessId="7700" RuntimeId="42.533330" x="1544" y="2994" width="319" height="1" />
			<Pane AcceleratorKey="" AccessKey="" AutomationId="tlpFluxoBtns" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="Consi" Orientation="None" ProcessId="7700" RuntimeId="42.533284" x="1541" y="2903" width="325" height="88">
				<Pane AcceleratorKey="" AccessKey="" AutomationId="pnlSeparator4" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533306" x="1784" y="2942" width="8" height="1" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="pnlSeparator3" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533296" x="1733" y="2942" width="8" height="1" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="pnlSeparator2" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533304" x="1662" y="2942" width="27" height="1" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="picBoxAutomatico" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="Consi" Orientation="None" ProcessId="7700" RuntimeId="42.533298" x="1563" y="2921" width="45" height="44" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="picBoxNP" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533346" x="1792" y="2921" width="43" height="44" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="picBoxNo" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533358" x="1741" y="2921" width="43" height="44" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="picBoxYes" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533606" x="1689" y="2921" width="44" height="44" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="picBoxSeta" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533282" x="1635" y="2921" width="27" height="44" />
				<Pane AcceleratorKey="" AccessKey="" AutomationId="pnlSeparator1" ClassName="WindowsForms10.Window.8.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="painel" Name="" Orientation="None" ProcessId="7700" RuntimeId="42.533278" x="1608" y="2942" width="27" height="1" />
				<Text AcceleratorKey="" AccessKey="" AutomationId="lblSelecionado" ClassName="WindowsForms10.STATIC.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="False" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="text" Name="selecionado" Orientation="None" ProcessId="7700" RuntimeId="42.533372" x="1689" y="2904" width="147" height="15" />
				<CheckBox AcceleratorKey="" AccessKey="" AutomationId="chkBoxAdicionarComentario" ClassName="WindowsForms10.BUTTON.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="caixa de seleção" Name="Adicionar Comentário" Orientation="None" ProcessId="7700" RuntimeId="42.533472" x="1692" y="2968" width="171" height="20" ToggleState="Off" IsAvailable="True" />
				<Text AcceleratorKey="" AccessKey="" AutomationId="lblAutomatico" ClassName="WindowsForms10.STATIC.app.0.83dd9_r9_ad1" FrameworkId="WinForm" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="False" IsOffscreen="False" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="text" Name="automático" Orientation="None" ProcessId="7700" RuntimeId="42.533248" x="1541" y="2904" width="94" height="15" />
			</Pane>
		</Pane>
	</Pane>
</Pane>	

ycoliveira avatar Mar 05 '18 17:03 ycoliveira

What did this line of code return: var foundResults = Driver.Session.FindElementsByAccessibilityId("picBoxYes");

That should get you every instance of the element (you can verify by replacing the element.Click in the foreach with Debug.Writeline(element.Text) or something to that affect).

If the FindElements got you back multiple elements, what failure did you see with the foreach loop?

PandaMagnus avatar Mar 07 '18 15:03 PandaMagnus

Hey there, It worked perfectly, it finds all the elements I want to click and click on them all but I having another problem. To click on all the elements he needs to scroll up/down the page. But instead of scrolling, it clicks on the same position where the boxes are but without scrolling, so he clicks on the box position in the screen but not on the box itself (The box is behind the place it clicks)

ycoliveira avatar Apr 16 '18 12:04 ycoliveira

Please open a new ticket if you are still experiencing the other problem @ycoliveira. Thanks!

hassanuz avatar Oct 15 '18 22:10 hassanuz