forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestXPathLocators.cs
125 lines (121 loc) · 5.18 KB
/
TestXPathLocators.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Text.RegularExpressions;
using System.Threading;
namespace Selenium.Tests
{
[TestFixture]
public class TesXPathLocators : SeleniumTestCaseBase
{
[Test]
public void ShouldBeAbleToUseXPathLocators()
{
selenium.Open("../tests/html/test_locators.html");
Assert.AreEqual(selenium.GetText("xpath=//a"), "this is the first element");
Assert.AreEqual(selenium.GetText("xpath=//a[@class='a2']"), "this is the second element");
Assert.AreEqual(selenium.GetText("xpath=//*[@class='a2']"), "this is the second element");
Assert.AreEqual(selenium.GetText("xpath=//a[2]"), "this is the second element");
Assert.AreEqual(selenium.GetText("xpath=//a[position()=2]"), "this is the second element");
Assert.IsFalse(selenium.IsElementPresent("xpath=//a[@href='foo']"));
Assert.AreEqual(selenium.GetAttribute("xpath=//a[contains(@href,'#id1')]/@class"), "a1");
Assert.IsTrue(selenium.IsElementPresent("xpath=//a[text()=\"this is the" + "\u00a0" + "third element\"]"));
Assert.AreEqual(selenium.GetText("//a"), "this is the first element");
Assert.AreEqual(selenium.GetAttribute("//a[contains(@href,'#id1')]/@class"), "a1");
Assert.AreEqual(selenium.GetText("xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td"), "theCellText");
selenium.Click("//input[@name='name2' and @value='yes']");
Assert.IsTrue(selenium.IsElementPresent("xpath=//*[text()=\"right\"]"));
Assert.AreEqual(selenium.GetValue("xpath=//div[@id='nested1']/div[1]//input[2]"), "nested3b");
Assert.AreEqual(selenium.GetValue("xpath=id('nested1')/div[1]//input[2]"), "nested3b");
Assert.AreEqual(selenium.GetValue("xpath=id('anotherNested')//div[contains(@id, 'useful')]//input"), "winner");
selenium.AssignId("xpath=//*[text()=\"right\"]", "rightButton");
Assert.IsTrue(selenium.IsElementPresent("rightButton"));
Assert.AreEqual(selenium.GetXpathCount("id('nested1')/div[1]//input"), 2);
Assert.AreEqual(selenium.GetXpathCount("//div[@id='nonexistent']"), 0);
Assert.IsTrue(selenium.IsElementPresent("xpath=//a[@href=\"javascript:doFoo('a', 'b')\"]"));
Assert.IsFalse(selenium.IsElementPresent("xpath=id('foo')//applet"));
try
{
Assert.IsTrue(selenium.IsElementPresent("xpath=id('foo')//applet2"));
Assert.Fail("expected Assert.Failure");
}
catch (Exception)
{
}
try
{
Assert.IsTrue(selenium.IsElementPresent("xpath=//a[0}"));
Assert.Fail("expected Assert.Failure");
}
catch (Exception)
{
}
// These cases are now covered by the "in play attributes" optimization.
// <p>Test toggling of ignoreAttributesWithoutValue. The test must be performed using the
// non-native ajaxslt engine. After the test, native xpaths are re-enabled.</p>
// <table cellpadding="1" cellspacing="1" border="1">
// <tbody>
// <tr>
// <td>allowNativeXpath</td>
// <td>false</td>
// <td> </td>
// </tr>
// <tr>
// <td>ignoreAttributesWithoutValue</td>
// <td>false</td>
// <td> </td>
// </tr>
// <tr>
// <td>verifyXpathCount</td>
// <td>//div[@id='ignore']/a[@class]</td>
// <td>2</td>
// </tr>
// <tr>
// <td>verifyText</td>
// <td>//div[@id='ignore']/a[@class][1]</td>
// <td>over the rainbow</td>
// </tr>
// <tr>
// <td>verifyText</td>
// <td>//div[@id='ignore']/a[@class][2]</td>
// <td>skies are blue</td>
// </tr>
// <tr>
// <td>verifyXpathCount</td>
// <td>//div[@id='ignore']/a[@class='']</td>
// <td>1</td>
// </tr>
// <tr>
// <td>verifyText</td>
// <td>//div[@id='ignore']/a[@class='']</td>
// <td>skies are blue</td>
// </tr>
// <tr>
// <td>ignoreAttributesWithoutValue</td>
// <td>true</td>
// <td> </td>
// </tr>
// <tr>
// <td>verifyXpathCount</td>
// <td>//div[@id='ignore']/a[@class]</td>
// <td>1</td>
// </tr>
// <tr>
// <td>verifyText</td>
// <td>//div[@id='ignore']/a[@class]</td>
// <td>over the rainbow</td>
// </tr>
// <tr>
// <td>verifyXpathCount</td>
// <td>//div[@id='ignore']/a[@class='']</td>
// <td>0</td>
// </tr>
// <tr>
// <td>allowNativeXpath</td>
// <td>true</td>
// <td> </td>
// </tr>
}
}
}