コード例 #1
0
 async def querySelectorAll(self, selector: str) -> List[ElementHandle]:
     """Get all elelments which matches `selector`."""
     remoteObject = await self._rawEvaluate(
         'selector => Array.from(document.querySelectorAll(selector))',
         selector,
     )
     response = await self._client.send(
         'Runtime.getProperties', {
             'objectId': remoteObject.get('objectId', ''),
             'ownProperties': True,
         })
     properties = response.get('result', {})
     result: List[ElementHandle] = []
     releasePromises = [helper.releaseObject(self._client, remoteObject)]
     for prop in properties:
         value = prop.get('value', {})
         if prop.get('enumerable') and value.get('subtype') == 'node':
             result.append(
                 ElementHandle(self, self._client, value, self._mouse,
                               self._touchscreen))
         else:
             releasePromises.append(
                 helper.releaseObject(self._client, value))
     await asyncio.gather(*releasePromises)
     return result
コード例 #2
0
ファイル: frame_manager.py プロジェクト: brijeshb42/pyppeteer
 async def S(self, selector):
     remote_object = await self._raw_evaluate(
         '''
         ({}) => document.querySelector({})
     '''.format(selector, selector), selector)
     if 'subtype' in remote_object and remote_object['subtype'] == 'node':
         return ElementHandle(self._client, remote_object, self._mouse)
     Helper.release_object(self._client, remote_object)
     return None
コード例 #3
0
 def createJSHandle(self,
                    context: ExecutionContext,
                    remoteObject: Dict = None) -> JSHandle:
     """Create JS handle associated to the context id and remote object."""
     if remoteObject is None:
         remoteObject = dict()
     if remoteObject.get('subtype') == 'node':
         return ElementHandle(context, self._client, remoteObject,
                              self._page, self)
     return JSHandle(context, self._client, remoteObject)
コード例 #4
0
 def createJSHandle(self, contextId: str, remoteObject: Dict = None
                    ) -> JSHandle:
     """Create JS handle associated to the context id and remote object."""
     if remoteObject is None:
         remoteObject = dict()
     context = self._contextIdToContext.get(contextId)
     if not context:
         raise ElementHandleError(f'missing context with id = {contextId}')
     if remoteObject.get('subtype') == 'node':
         return ElementHandle(context, self._client, remoteObject,
                              self._page, self)
     return JSHandle(context, self._client, remoteObject)
コード例 #5
0
    async def querySelector(self, selector: str) -> Optional[ElementHandle]:
        """Get element which matches `selector` string.

        If `selector` matches multiple elements, return first-matched element.
        """
        remoteObject = await self._rawEvaluate(
            'selector => document.querySelector(selector)', selector)
        if remoteObject.get('subtype') == 'node':
            return ElementHandle(self, self._client, remoteObject, self._mouse,
                                 self._touchscreen)
        await helper.releaseObject(self._client, remoteObject)
        return None
コード例 #6
0
 def createJSHandle(self,
                    contextId: str,
                    remoteObject: Dict = None) -> JSHandle:
     'Create JS handle associated to the context id and remote object.'
     if (remoteObject is None):
         remoteObject = dict()
     context = self._contextIdToContext.get(contextId)
     if (not context):
         raise ElementHandleError(''.join(
             ['missing context with id = ', '{}'.format(contextId)]))
     if (remoteObject.get('subtype') == 'node'):
         return ElementHandle(context, self._client, remoteObject,
                              self._page, self)
     return JSHandle(context, self._client, remoteObject)