How to use _findFirstR method in pyatom

Best Python code snippet using pyatom_python

AXClasses.py

Source:AXClasses.py Github

copy

Full Screen

...598 def _matchOther(self, obj, **kwargs):599 """Perform _match but on another object, not self."""600 if obj is not None:601 # Need to check that the returned UI element wasn't destroyed first:602 if self._findFirstR(**kwargs):603 return obj._match(**kwargs)604 return False605 def _generateFind(self, **kwargs):606 """Generator which yields matches on AXChildren."""607 for needle in self._generateChildren():608 if needle._match(**kwargs):609 yield needle610 def _generateFindR(self, **kwargs):611 """Generator which yields matches on AXChildren and their children."""612 for needle in self._generateChildrenR():613 if needle._match(**kwargs):614 yield needle615 def _findAll(self, **kwargs):616 """Return a list of all children that match the specified criteria."""617 result = []618 for item in self._generateFind(**kwargs):619 result.append(item)620 return result621 def _findAllR(self, **kwargs):622 """Return a list of all children (recursively) that match the specified623 criteria.624 """625 result = []626 for item in self._generateFindR(**kwargs):627 result.append(item)628 return result629 def _findFirst(self, **kwargs):630 """Return the first object that matches the criteria."""631 for item in self._generateFind(**kwargs):632 return item633 def _findFirstR(self, **kwargs):634 """Search recursively for the first object that matches the criteria."""635 for item in self._generateFindR(**kwargs):636 return item637 def _getApplication(self):638 """Get the base application UIElement.639 If the UIElement is a child of the application, it will try640 to get the AXParent until it reaches the top application level641 element.642 """643 app = self644 while True:645 try:646 app = app.AXParent647 except _a11y.ErrorUnsupported:648 break649 return app650 def _menuItem(self, menuitem, *args):651 """Return the specified menu item.652 Example - refer to items by name:653 app._menuItem(app.AXMenuBar, 'File', 'New').Press()654 app._menuItem(app.AXMenuBar, 'Edit', 'Insert', 'Line Break').Press()655 Refer to items by index:656 app._menuitem(app.AXMenuBar, 1, 0).Press()657 Refer to items by mix-n-match:658 app._menuitem(app.AXMenuBar, 1, 'About TextEdit').Press()659 """660 self._activate()661 for item in args:662 # If the item has an AXMenu as a child, navigate into it.663 # This seems like a silly abstraction added by apple's a11y api.664 if menuitem.AXChildren[0].AXRole == 'AXMenu':665 menuitem = menuitem.AXChildren[0]666 # Find AXMenuBarItems and AXMenuItems using a handy wildcard667 role = 'AXMenu*Item'668 try:669 menuitem = menuitem.AXChildren[int(item)]670 except ValueError:671 menuitem = menuitem.findFirst(AXRole='AXMenu*Item',672 AXTitle=item)673 return menuitem674 def _activate(self):675 """Activate the application (bringing menus and windows forward)."""676 ra = AppKit.NSRunningApplication677 app = ra.runningApplicationWithProcessIdentifier_(678 self._getPid())679 # NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps680 # == 3 - PyObjC in 10.6 does not expose these constants though so I have681 # to use the int instead of the symbolic names682 app.activateWithOptions_(3)683 def _getBundleId(self):684 """Return the bundle ID of the application."""685 ra = AppKit.NSRunningApplication686 app = ra.runningApplicationWithProcessIdentifier_(687 self._getPid())688 return app.bundleIdentifier()689 def _getLocalizedName(self):690 """Return the localized name of the application."""691 return self._getApplication().AXTitle692 def __getattr__(self, name):693 """Handle attribute requests in several ways:694 1. If it starts with AX, it is probably an a11y attribute. Pass695 it to the handler in _a11y which will determine that for sure.696 2. See if the attribute is an action which can be invoked on the697 UIElement. If so, return a function that will invoke the attribute.698 """699 if name.startswith('AX'):700 try:701 attr = self._getAttribute(name)702 return attr703 except AttributeError:704 pass705 # Populate the list of callable actions:706 actions = []707 try:708 actions = self._getActions()709 except Exception:710 pass711 if name.startswith('AX') and (name[2:] in actions):712 errStr = 'Actions on an object should be called without AX ' \713 'prepended'714 raise AttributeError(errStr)715 if name in actions:716 def performSpecifiedAction():717 # activate the app before performing the specified action718 self._activate()719 return self._performAction(name)720 return performSpecifiedAction721 else:722 raise AttributeError('Object %s has no attribute %s' % (self, name))723 def __setattr__(self, name, value):724 """Set attributes on the object."""725 if name.startswith('AX'):726 return self._setAttribute(name, value)727 else:728 _a11y.AXUIElement.__setattr__(self, name, value)729 def __repr__(self):730 """Build a descriptive string for UIElements."""731 title = repr('')732 role = '<No role!>'733 c = repr(self.__class__).partition('<class \'')[-1].rpartition('\'>')[0]734 try:735 title = repr(self.AXTitle)736 except Exception:737 try:738 title = repr(self.AXValue)739 except Exception:740 try:741 title = repr(self.AXRoleDescription)742 except Exception:743 pass744 try:745 role = self.AXRole746 except Exception:747 pass748 if len(title) > 20:749 title = title[:20] + '...\''750 return '<%s %s %s>' % (c, role, title)751class NativeUIElement(BaseAXUIElement):752 """NativeUIElement class - expose the accessibility API in the simplest,753 most natural way possible.754 """755 def getAttributes(self):756 """Get a list of the attributes available on the element."""757 return self._getAttributes()758 def getActions(self):759 """Return a list of the actions available on the element."""760 return self._getActions()761 def setString(self, attribute, string):762 """Set the specified attribute to the specified string."""763 return self._setString(attribute, string)764 def findFirst(self, **kwargs):765 """Return the first object that matches the criteria."""766 return self._findFirst(**kwargs)767 def findFirstR(self, **kwargs):768 """Search recursively for the first object that matches the769 criteria.770 """771 return self._findFirstR(**kwargs)772 def findAll(self, **kwargs):773 """Return a list of all children that match the specified criteria."""774 return self._findAll(**kwargs)775 def findAllR(self, **kwargs):776 """Return a list of all children (recursively) that match777 the specified criteria.778 """779 return self._findAllR(**kwargs)780 def getElementAtPosition(self, coord):781 """Return the AXUIElement at the given coordinates.782 If self is behind other windows, this function will return self.783 """784 return self._getElementAtPosition(float(coord[0]), float(coord[1]))785 def activate(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful