Every line of 'selenium hover over element' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
145 def hover_element_and_click(driver, element, click_selector, 146 click_by=By.CSS_SELECTOR, 147 timeout=settings.SMALL_TIMEOUT): 148 """ 149 Similar to hover_and_click(), but assumes top element is already found. 150 """ 151 start_ms = time.time() * 1000.0 152 stop_ms = start_ms + (timeout * 1000.0) 153 hover = ActionChains(driver).move_to_element(element) 154 hover.perform() 155 for x in range(int(timeout * 10)): 156 try: 157 element = driver.find_element(by=click_by, value=click_selector) 158 element.click() 159 return element 160 except Exception: 161 now_ms = time.time() * 1000.0 162 if now_ms >= stop_ms: 163 break 164 time.sleep(0.1) 165 raise NoSuchElementException( 166 "Element {%s} was not present after %s seconds!" % 167 (click_selector, timeout))
510 def hover_on_element(self, locator: dict): 511 """Hover on a particular element. 512 513 :param locator: dictionary of identifier type 514 and value ({'by':'id', 'value':'start-of-content.'}). 515 :type locator: dict 516 """ 517 self.locator_check(locator) 518 self.page_readiness_wait() 519 if isinstance(locator, dict): 520 try: 521 ActionChains(self.driver).move_to_element( 522 self.__find_element(locator)).perform() 523 except selenium_exceptions.NoSuchElementException: 524 AssertionError( 525 "Element{} not found".format(locator['by']) + 526 '=' + locator['locatorvalue']) 527 else: 528 raise AssertionError("Locator type should be dictionary")
205 def mouseover_element(self, element_selector): 206 chain = ActionChains(self.webdriver) 207 chain.move_to_element(self._get_element(element_selector)) 208 chain.perform()
25 def test_mouse_hover(self): 26 # Open url 27 self.driver.get('http://the-internet.herokuapp.com/hovers') 28 29 # Move mouse over second image 30 image2 = self.driver.find_element_by_xpath("//div[@class='figure'][2]/img") 31 ActionChains(self.driver).move_to_element(image2).perform() 32 33 # Check the new element 34 caption2 = self.driver.find_element_by_xpath("//div[@class='figure'][2]/div[@class='figcaption']/h5") 35 self.assertEqual(caption2.text, 'name: user2')