-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium3.py
More file actions
36 lines (31 loc) · 1.12 KB
/
selenium3.py
File metadata and controls
36 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from selenium import webdriver
from page_objects import PageObject, PageElement
class LoginPage(PageObject):
'''
Page Object Model sample code package (page_objects)
https://page-objects.readthedocs.io/en/latest/tutorial.html
https://media.readthedocs.org/pdf/page-objects/latest/page-objects.pdf
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form type="POST" action="/login">
<input type="text" name="username" id="user-input"></input>
<input type="password" name="password"></input>
<input type="submit">Submit</input>
</form>
</body>
</html>
'''
username = PageElement(id_='user-input')
password = PageElement(name='password')
login = PageElement(css='input[type="submit"]')
form = PageElement(tag_name='form')
driver = webdriver.PhantomJS()
driver.get("http://example.com")
page = LoginPage(driver)
page.username = 'secret'
page.password = 'squirrel'
assert page.username.text == 'secret'
page.login.click()