课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

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

Text boxes

Text boxes

- [Instructor] WebDriver is not only used to locate elements, but more importantly, to interact with them. Let's look at this text box. WebDriver offers methods to read, write, and clear a text box. Let's do each of those with Selenium WebDriver. We can locate this element by its name, so let's say WebElement textbox = driver.findElement(By.name), and its name was "id-name1". Then to read the value of this element, we say textbox.getText(), and this will return the string of the text that's inside of that text box. To remove the text that's in the field, we call textbox.clear(). And to set text in the textbox, we say textbox.sendKeys, and then we provide the text to write. So I'm going to put my name, feel free to put yours. I'm going to comment out this quit() command so that we can see what happens when we run this. So we'll click Run, and switch over to our browser tab. And notice here, you see "angie" was written to that text box.

内容