Skip to content

Commit 7e65050

Browse files
committed
Add hover_element_and_click() to page_actions
1 parent 84ca2d3 commit 7e65050

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

seleniumbase/fixtures/page_actions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ def hover_and_click(driver, hover_selector, click_selector,
138138
(click_selector, timeout))
139139

140140

141+
def hover_element_and_click(driver, element, click_selector,
142+
click_by=By.CSS_SELECTOR,
143+
timeout=settings.SMALL_TIMEOUT):
144+
"""
145+
Similar to hover_and_click(), but assumes top element is already found.
146+
"""
147+
start_ms = time.time() * 1000.0
148+
stop_ms = start_ms + (timeout * 1000.0)
149+
hover = ActionChains(driver).move_to_element(element)
150+
hover.perform()
151+
for x in range(int(timeout * 10)):
152+
try:
153+
element = driver.find_element(by=click_by,
154+
value="%s" % click_selector).click()
155+
return element
156+
except Exception:
157+
now_ms = time.time() * 1000.0
158+
if now_ms >= stop_ms:
159+
break
160+
time.sleep(0.1)
161+
raise NoSuchElementException(
162+
"Element {%s} was not present after %s seconds!" %
163+
(click_selector, timeout))
164+
165+
141166
def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
142167
timeout=settings.LARGE_TIMEOUT):
143168
"""

0 commit comments

Comments
 (0)