findElement 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/findElement.rb +42 -37
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f9ef2944e06d806563bb23f039029a4a4876a9f07e67494b68eb8accb02a94a
|
4
|
+
data.tar.gz: 709d4e19f9a52e862e19fc56f73fd6b39949c995aea586e46333f571b623fe15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75d55650f9dfe7e38668de2b703859d7b7f074dc50f2dbd7140c2795af7187174fbc21e3cb15b700a0d1dc572a0e0519a61eb3ec7bc42219f56867f749d88fb7
|
7
|
+
data.tar.gz: 82ca022388e31d365c0c3a3a305663d198f5a2fb038ae52f3b0e2e4abc8d6e315fe63b6210c497574f9ff152ac34d0f59fb9b2e1c7d7a05fd3c5c7e0f6c7edad
|
data/lib/findElement.rb
CHANGED
@@ -28,48 +28,53 @@ findElement("adv-spinner loadingSpinner").text ==> picture
|
|
28
28
|
|
29
29
|
def findElement text
|
30
30
|
|
31
|
+
if text.include? '@xpath'
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if cond
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return find(:xpath, "//#{tag}[
|
33
|
+
return find(:xpath, text.split('@xpath')[0])
|
34
|
+
|
35
|
+
else
|
36
|
+
|
37
|
+
begin
|
38
|
+
Timeout.timeout(2) do
|
39
|
+
return find(:xpath, "//*[contains(text(),'#{text}')]", visible: true)
|
40
|
+
end
|
41
|
+
rescue
|
42
|
+
soruce = page.html
|
43
|
+
cond = soruce.split(text)
|
44
|
+
if cond.count == 2
|
45
|
+
tag = cond[0].split("<").last
|
46
|
+
tag = tag.split[0].delete(">")
|
47
|
+
|
48
|
+
if cond[0][cond[0].length - 1] == '"'
|
49
|
+
attr = cond[0].split('<').last
|
50
|
+
attr = attr.split('="').last
|
51
|
+
attr = attr.split.last
|
52
|
+
return find(:xpath, "//#{tag}[@#{attr}='#{text}']", visible: true)
|
52
53
|
else
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
attr = cond[0].split("<").last
|
55
|
+
unless attr.include? "=\""
|
56
|
+
return find(:xpath, "//#{tag}[contains(text(),'#{text}')]", visible: true)
|
57
|
+
else
|
58
|
+
key = attr.split('="')[0].split[1]
|
59
|
+
value = attr.split(key)[1].split('"')[1]
|
60
|
+
return find(:xpath, "//#{tag}[@#{key}='#{value}'][contains(text(),'#{text}')]", visible: true)
|
61
|
+
end
|
56
62
|
end
|
63
|
+
else
|
64
|
+
|
65
|
+
attr_name = ['id', 'name', 'class', 'href', 'data-title', 'text-area', 'text', 'data-dismiss', 'style', 'title', 'type', 'placeholder', 'value', 'list', 'dropzone', 'draggable', 'download', 'form', 'headers']
|
66
|
+
i = 0
|
67
|
+
attr_name.each do |attribute|
|
68
|
+
@element = attribute + '="' + text + '"'
|
69
|
+
break if soruce.include? @element
|
70
|
+
i += 1
|
71
|
+
next if i < attr_name.count
|
72
|
+
raise('could not find :' + @element)
|
73
|
+
end
|
74
|
+
return find(:xpath, "//*[@#{@element}]", visible: true)
|
57
75
|
end
|
58
|
-
|
59
|
-
|
60
|
-
attr_name = ['id', 'name', 'class', 'href', 'data-title','text-area','text', 'data-dismiss', 'style', 'title', 'type', 'placeholder', 'value', 'list', 'dropzone', 'draggable', 'download', 'form', 'headers']
|
61
|
-
i = 0
|
62
|
-
attr_name.each do |attribute|
|
63
|
-
@element = attribute + '="' + text + '"'
|
64
|
-
break if soruce.include? @element
|
65
|
-
i += 1
|
66
|
-
next if i < attr_name.count
|
67
|
-
raise('could not find :' + @element)
|
68
|
-
end
|
69
|
-
return find(:xpath, "//*[@#{@element}]", visible: true)
|
76
|
+
|
70
77
|
end
|
71
78
|
|
72
79
|
end
|
73
|
-
|
74
|
-
|
75
80
|
end
|