课程: Test Automation with Selenium WebDriver for Java
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Drag and drop
- [Instructor] Drag and drop is an interaction often used to rearrange items on a webpage. Let's use Selenium WebDriver to drag LeftItem 1 into the right column. Let's first find the LeftItem 1 and RightItem 1 elements. So we can say WebElement leftItem = driver.findElement(By.id), and the ID is "leftitem-1". And we'll do the same for the right element. So, rightItem = driver.findElement, also (By.id), and this is rightitem-1. To drag the left item into the right column, we can say new Actions, pass in the (driver).dragAndDrop. The dragAndDrop method takes two arguments. The first is the element that you want to drag, and the second is the element that you want to drop the first element on. So we specify here, left item to drag and right item to drop on. Then, let's call perform to execute this action. Now let's print the right column to see if the left item was moved. So we can say var rightItems = driver.findElements, plural. And we'll say (By.cssSelector). And we want to find all…