def hover_and_click(driver, hover_selector, click_selector,<EOL>hover_by=By.CSS_SELECTOR, click_by=By.CSS_SELECTOR,<EOL>timeout=settings.SMALL_TIMEOUT):
start_ms = time.time() * <NUM_LIT><EOL>stop_ms = start_ms + (timeout * <NUM_LIT>)<EOL>element = driver.find_element(by=hover_by, value=hover_selector)<EOL>hover = ActionChains(driver).move_to_element(element)<EOL>hover.perform()<EOL>for x in range(int(timeout * <NUM_LIT:10>)):<EOL><INDENT>try:<EOL><INDENT>element = driver.find_element(by=click_by, value=click_selector)<EOL>element.click()<EOL>return element<EOL><DEDENT>except Exception:<EOL><INDENT>now_ms = time.time() * <NUM_LIT><EOL>if now_ms >= stop_ms:<EOL><INDENT>break<EOL><DEDENT>time.sleep(<NUM_LIT:0.1>)<EOL><DEDENT><DEDENT>raise NoSuchElementException(<EOL>"<STR_LIT>" %<EOL>(click_selector, timeout))<EOL>
Fires the hover event for a specified element by a given selector, then
clicks on another element specified. Useful for dropdown hover based menus.
@Params
driver - the webdriver object (required)
hover_selector - the css selector to hover over (required)
click_selector - the css selector to click on (required)
hover_by - the method to search by (Default: By.CSS_SELECTOR)
click_by - the method to search by (Default: By.CSS_SELECTOR)
timeout - number of seconds to wait for click element to appear after hover