课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

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

Initializing elements

Initializing elements

- [Instructor] Let's create a page object class that contains the web elements needed to automate entering a username and password and clicking the login button. We'll need the locators for each element. The username field has an ID of username-field. The password field has an ID of password-dash field, and the login button has an ID of login-form-submit. In this LoginPage class, which lives in the source main Java package, we'll define each of the elements as global variables so that they are accessible by any methods we create for this page. And instead of using web elements as the type we'll use By. So I'm going to say By usernameField. When you define objects as web element, they are located and initialized immediately when the page object class is instantiated. If the page hasn't fully loaded or if the elements aren't immediately present in the dom, this can lead to an exception. By defining the elements as By objects, the actual search for the element happens when the method…

内容