-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlLink.py
More file actions
57 lines (51 loc) · 1.79 KB
/
HtmlLink.py
File metadata and controls
57 lines (51 loc) · 1.79 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding: utf-8
from string import Template
class HtmlLink:
def __init__(self, show_name, ids, text, href):
self.show_name = show_name
self.ids = ids
self.text = text
self.href = href
pass
def __repr__(self):
ret = 'show_name:', self.show_name
return str(ret)
def get_private_property(self):
private_property = """
private string ${show_name} = ${condition_exp}"""
show_name = ''
condition_exp=''
if self.ids:
show_name = 'id_' + self.show_name
condition_exp = '"id=' + self.ids + '"'
elif self.text:
show_name = 'text_' + self.show_name
condition_exp ='"TextContent=' + self.text + '"'
elif self.href:
show_name = 'href_' + self.show_name
condition_exp ='"href=' + self.href + '"'
#利用Template替换掉原来占位符
return Template(private_property).substitute({'show_name': show_name, 'condition_exp': condition_exp})
def get_public_property(self):
public_property = """
public HtmlAnchor ${show_name}
{
get
{
return Get<HtmlAnchor>(TagA,${condition_exp});
}
}
"""
condition_exp = ''
#若有id属性,直接用id属性,否则若有text属性,就用text属性,否则利用href属性
if self.ids:
condition_exp = 'id_' + self.show_name
pass
elif self.text:
condition_exp = 'text_' + self.show_name
pass
elif self.href:
condition_exp = 'href_' + self.show_name
pass
#利用Template替换掉原来占位符
return Template(public_property).substitute({'show_name': self.show_name, 'condition_exp': condition_exp})