课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Hover

Hover

- [Instructor] Hovering over an element is a common web interaction that can reveal hidden content or display tool tips. For example, if I hover over this green box, a red one appears. Let's explore how to use WebDriver to hover over elements. Let's start by finding the element by its ID of redBox. So, we can say var redBox equals driver.findElement, By.Id and we'll pass in redbox, all lowercase. And let's print out the elements background color before we hover. So, we'll do a print statement and in here we'll say redBox.getCSSValue. And inside of a set of quotation marks, we can say background-color. To hover over this element, we'll need to use the actions API provided by WebDriver, which allows for interactions that require precise control over mouse and keyboard events. We'll instantiate actions and provide our driver. So, say, new Actions and we give it our driver. (keyboard clicking) And then we want to call the moveToElement method and pass in the element that we want to hover…

内容