课程: Test Automation with Selenium WebDriver for Java
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Copy and paste
- [Instructor] Selenium web driver enables you to perform complex actions like copying and pasting text. Let's write a script that copies the text from the text area whose ID is WithText and paste it into the empty text area. Let's create web elements for the two text areas. So the first one we'll call field1 and we'll say driver.findElement By.id and its ID is withText. The second one we'll call field2, and this one we say driver.findElement and By.id and its text is emptyTextArea. To copy text, we can use keyboard shortcut control C, or on Mac OS, command C. Web Driver provides the Keys class, which allows us to simulate keyboard key presses, and also the Platform class, which can detect our current operating system. Let's use these two classes to help Selenium determine which key to use. So we'll say Keys command/control, then we're going to get the current operating system, so that's Platform.getCurrent, and we're going to check if it's a Mac. So we'll say is, and then inside of…