@@ -7,13 +7,12 @@ def test_basic(self):
7
7
self .open ('http://xkcd.com/353/' ) # Navigate to the web page
8
8
self .assert_element ('img[alt="Python"]' ) # Assert element on page
9
9
self .click ('a[rel="license"]' ) # Click element on page
10
- text = self .get_text ("div center" ) # Grab text from page element
11
- self .assertTrue ("reuse any of my drawings" in text )
12
- self .open ('http://xkcd.com/1481/' )
13
- title = self .get_attribute ('#comic img' , 'title' ) # Grab an attribute
14
- self .assertTrue ('connections to the server' in title )
15
- self .click_link_text ('Blag' ) # Click on link with the text
16
- self .assert_text ('The blag of the webcomic' , 'h2' ) # Assert text in h2
10
+ self .assert_text ('free to copy' , 'div center' ) # Assert text on page
11
+ self .open ("http://xkcd.com/1481/" )
12
+ title = self .get_attribute ("#comic img" , "title" ) # Grab an attribute
13
+ self .assertTrue ("86,400 seconds per day" in title )
14
+ self .click ('link=Blag' ) # Click on link with the text
15
+ self .assert_text ('The blag of the webcomic' , 'h2' )
17
16
self .update_text ('input#s' , 'Robots!\n ' ) # Fill in field with the text
18
17
self .assert_text ('Hooray robots!' , '#content' )
19
18
self .open ('http://xkcd.com/1319/' )
@@ -26,33 +25,25 @@ def test_basic(self):
26
25
# **** NOTES / USEFUL INFO ****
27
26
#
28
27
# 1. By default, CSS Selectors are used to identify elements.
29
- # You can use other identification options like PARTIAL_LINK_TEXT:
28
+ # Other options include: "LINK_TEXT", "PARTIAL_LINK_TEXT", "NAME",
29
+ # "CLASS_NAME", and "ID", but most of those can be expressed as CSS.
30
+ # Here's an example of changing the "by":
30
31
# [
31
32
# from selenium.webdriver.common.by import By
32
33
# ...
33
34
# self.click('Next', by=By.PARTIAL_LINK_TEXT)
34
35
# ]
35
- # For the full list of `By` options, type ``dir(By)`` into a python
36
- # command prompt after importing it (or in ipdb debugger mode). Ex:
37
- # {
38
- # >>> dir(By)
39
- # ['CLASS_NAME', 'CSS_SELECTOR', 'ID', 'LINK_TEXT', 'NAME', ...
40
- # }
41
36
# XPath is used by default if the arg starts with "/", "./", or "(":
42
37
# [
43
38
# self.click('/html/body/div[3]/div[4]/p[2]/a')
44
39
# ]
45
- # But if you want XPath-clicking to be more clear in the code, use:
46
- # [
47
- # self.click_xpath('/html/body/div[3]/div[4]/p[2]/a')
48
- # ]
49
40
#
50
41
# If you're completely new to CSS selectors, right-click on a
51
- # web page and select "Inspect Element " to see the CSS in the html.
42
+ # web page and select "Inspect" to see the CSS in the html.
52
43
#
53
44
# 2. Most methods have the optional `timeout` argument. Ex:
54
45
# [
55
- # self.get_text('center', timeout=15)
46
+ # self.get_text('div center', timeout=15)
56
47
# ]
57
48
# The `timeout` argument tells the method how many seconds to wait
58
49
# for an element to appear before raising an exception. This is
@@ -62,33 +53,28 @@ def test_basic(self):
62
53
#
63
54
# 3. There's usually more than one way to do the same thing. Ex:
64
55
# [
65
- # header_text = self.get_text('header h2')
66
- # self.assertTrue('The blag of the webcomic' in header_text)
56
+ # self.assert_text('free to copy', 'div center')
67
57
# ]
68
- # Can be simplified to:
69
- # [
70
- # self.assert_text('The blag of the webcomic', 'header_text')
71
- # ]
72
- #
73
- # The following line:
58
+ # Is the same as:
74
59
# [
75
- # title = self.get_attribute('#comic img', 'title')
60
+ # text = self.get_text("div center")
61
+ # self.assertTrue("free to copy" in text)
76
62
# ]
77
- # Can also be written as :
63
+ # Or :
78
64
# [
79
- # element = self.find_element('#comic img')
80
- # title = element.get_attribute('title' )
65
+ # text = self.find_element('div center').text
66
+ # assert("free to copy" in text )
81
67
# ]
82
68
#
83
69
# And the following line:
84
70
# [
85
- # text = self.get_text("div center ")
71
+ # title = self.get_attribute("#comic img", "title ")
86
72
# ]
87
73
# Can also be written as:
88
74
# [
89
- # text = self.find_element('div center').text
75
+ # element = self.find_element("#comic img")
76
+ # title = element.get_attribute("title")
90
77
# ]
91
- # ...and in many more ways!
92
78
#
93
79
# For backwards-compatibilty, some methods have multiple names.
94
80
# Ex: wait_for_element_visible() is the same as find_element().
0 commit comments