Repository navigation
Expand file tree
/
Copy pathMockWebElement.cs
More file actions
88 lines (75 loc) · 2.12 KB
/
Copy pathMockWebElement.cs
File metadata and controls
88 lines (75 loc) · 2.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using OpenQA.Selenium;
using Scalpel;
namespace ASI.SeleniumExtensions
{
[Remove]
internal class MockWebElement : IWebElement
{
private readonly SearchableDocument _dom;
public MockWebElement(string html)
{
_dom = new SearchableDocument(html);
}
public IWebElement FindElement(By by)
{
return new MockWebElement(_dom.FindElements(by).First().Text);
}
public ReadOnlyCollection<IWebElement> FindElements(By by)
{
var elems = _dom.FindElements(by);
var list = elems.Select(elem => new MockWebElement(elem.Text)).Cast<IWebElement>().ToArray();
return new ReadOnlyCollection<IWebElement>(list);
}
public void Clear()
{
throw new NotImplementedException();
}
public void SendKeys(string text)
{
throw new NotImplementedException();
}
public void Submit()
{
throw new NotImplementedException();
}
public void Click()
{
throw new NotImplementedException();
}
public string GetAttribute(string attributeName)
{
switch (attributeName)
{
case "outerHTML":
return _dom.BaseElement.Text;
case "innerHTML":
return _dom.BaseElement.InnerText;
default:
return _dom.BaseElement.Attributes.ContainsKey(attributeName)
? _dom.BaseElement.Attributes[attributeName]
: string.Empty;
}
}
public string GetProperty(string propertyName)
{
return _dom.BaseElement.Attributes.ContainsKey(propertyName)
? _dom.BaseElement.Attributes[propertyName]
: string.Empty;
}
public string GetCssValue(string propertyName)
{
return _dom.BaseElement.Classes.FirstOrDefault(c => c.Contains(propertyName));
}
public string TagName => _dom.BaseElement.ElementType;
public string Text => _dom.BaseElement.InnerText;
public bool Enabled { get; }
public bool Selected { get; }
public Point Location { get; }
public Size Size { get; }
public bool Displayed { get; }
}
}