MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / query_selector

Method query_selector

seleniumbase/undetected/cdp_driver/tab.py:435–479  ·  view source on GitHub ↗

Find a single element based on a CSS Selector string. :param selector: CSS Selector(s) :type selector: str

(
        self,
        selector: str,
        _node: Optional[Union[cdp.dom.Node, element.Element]] = None,
    )

Source from the content-addressed store, hash-verified

433 return items
434
435 async def query_selector(
436 self,
437 selector: str,
438 _node: Optional[Union[cdp.dom.Node, element.Element]] = None,
439 ):
440 """
441 Find a single element based on a CSS Selector string.
442 :param selector: CSS Selector(s)
443 :type selector: str
444 """
445 selector = selector.strip()
446 if not _node:
447 doc: cdp.dom.Node = await self.send(cdp.dom.get_document(-1, True))
448 else:
449 doc = _node
450 if _node.node_name == "IFRAME":
451 doc = _node.content_document
452 node_id = None
453 try:
454 node_id = await self.send(
455 cdp.dom.query_selector(doc.node_id, selector)
456 )
457 except ProtocolException as e:
458 if _node is not None:
459 if "could not find node" in e.message.lower():
460 if getattr(_node, "__last", None):
461 del _node.__last
462 return []
463 # If supplied node is not found,
464 # the dom has changed since acquiring the element,
465 # therefore, update our passed node and try again.
466 await _node.update()
467 _node.__last = (
468 True # Make sure this isn't turned into infinite loop.
469 )
470 return await self.query_selector(selector, _node)
471 else:
472 await self.send(cdp.dom.disable())
473 raise
474 if not node_id:
475 return
476 node = util.filter_recurse(doc, lambda n: n.node_id == node_id)
477 if not node:
478 return
479 return element.create(node, self, doc)
480
481 async def find_elements_by_text(
482 self,

Callers 10

wait_forMethod · 0.95
nested_clickMethod · 0.80
get_nested_elementMethod · 0.80
query_selector_asyncMethod · 0.80
test_presentation_4Method · 0.80
raw_ralphlauren.pyFile · 0.80
raw_southwest.pyFile · 0.80
raw_priceline.pyFile · 0.80
raw_bestwestern.pyFile · 0.80
raw_cdp_zillow.pyFile · 0.80

Calls 4

updateMethod · 0.80
createMethod · 0.80
sendMethod · 0.45
get_documentMethod · 0.45

Tested by 1

test_presentation_4Method · 0.64