You can download this code by clicking the button below.
This code is now available for download.
This function randomly selects an element from the specified selector. If no elements match, it returns None.
Technology Stack : Selenium, Python
Code Type : Selenium Function
Code Difficulty : Intermediate
def random_select_element(driver, by, value):
elements = driver.find_elements(by, value)
return elements[random.randint(0, len(elements) - 1)] if elements else None