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

Method click_nth_visible_element

seleniumbase/core/sb_cdp.py:491–507  ·  view source on GitHub ↗

Finds all matching page elements and clicks the nth visible one. Example: self.click_nth_visible_element('[type="checkbox"]', 5) (Clicks the 5th visible checkbox on the page.)

(self, selector, number, scroll=True)

Source from the content-addressed store, hash-verified

489 element.click()
490
491 def click_nth_visible_element(self, selector, number, scroll=True):
492 """Finds all matching page elements and clicks the nth visible one.
493 Example: self.click_nth_visible_element('[type="checkbox"]', 5)
494 (Clicks the 5th visible checkbox on the page.)"""
495 elements = self.find_visible_elements(selector)
496 if len(elements) < number:
497 raise Exception(
498 "Not enough matching {%s} elements to "
499 "click number %s!" % (selector, number)
500 )
501 number = number - 1
502 if number < 0:
503 number = 0
504 element = elements[number]
505 if scroll:
506 element.scroll_into_view()
507 element.click()
508
509 def click_link(self, link_text):
510 self.find_elements_by_text(link_text, "a")[0].click()

Callers

nothing calls this directly

Calls 3

find_visible_elementsMethod · 0.95
scroll_into_viewMethod · 0.45
clickMethod · 0.45

Tested by

no test coverage detected