Skip to content

Commit 016e75e

Browse files
committed
Fixed the tests to fetch the same element as the tests in other programming languages
1 parent 3984f93 commit 016e75e

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

examples/javascript/test/elements/locators.spec.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('Element Locator Test', function () {
66
let driver = await new Builder().forBrowser('chrome').build();
77
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
88
const element = await driver.findElement(By.className('information'));
9-
109
const tag = await element.getTagName();
1110
const id = await element.getAttribute("id");
1211
const value = await element.getAttribute("value");
@@ -50,69 +49,71 @@ describe('Element Locator Test', function () {
5049
it('Check if element can be found by name', async function () {
5150
let driver = await new Builder().forBrowser('chrome').build();
5251
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
53-
const element = await driver.findElement(By.name("gender"));
52+
const element = await driver.findElement(By.name("newsletter"));
5453

5554
const tag = await element.getTagName();
5655
const type = await element.getAttribute("type");
5756
const value = await element.getAttribute("value");
5857

5958
assert.equal(tag, "input");
60-
assert.equal(type, "radio");
61-
assert.equal(value, "m");
59+
assert.equal(type, "checkbox");
60+
assert.equal(value, "1");
6261
await driver.quit();
6362
});
6463

65-
it('Check if element can be found by xpath', async function () {
64+
65+
66+
it('Check if element can be found by link text', async function () {
6667
let driver = await new Builder().forBrowser('chrome').build();
6768
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
68-
const element = await driver.findElement(By.xpath('//input[@name="newsletter"]'));
69+
const element = await driver.findElement(By.linkText("Selenium Official Page"));
6970

7071
const tag = await element.getTagName();
71-
const type = await element.getAttribute("type");
72-
const value = await element.getAttribute("value");
72+
const href = await element.getAttribute("href");
7373

74-
assert.equal(tag, "input");
75-
assert.equal(type, "checkbox");
76-
assert.equal(value, "1");
74+
assert.equal(tag, "a");
75+
assert.equal(href, "https://www.selenium.dev/");
7776
await driver.quit();
7877
});
7978

80-
it('Check if element can be found by tag name', async function () {
79+
it('Check if element can be found by partial link text', async function () {
8180
let driver = await new Builder().forBrowser('chrome').build();
8281
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
83-
const element = await driver.findElement(By.tagName("h2"));
82+
const element = await driver.findElement(By.partialLinkText("Official Page"));
8483

8584
const tag = await element.getTagName();
86-
const text = await element.getText();
85+
const href = await element.getAttribute("href");
8786

88-
assert.equal(tag, "h2");
89-
assert.equal(text, "Contact Selenium");
87+
assert.equal(tag, "a");
88+
assert.equal(href, "https://www.selenium.dev/");
9089
await driver.quit();
9190
});
9291

93-
it('Check if element can be found by link text', async function () {
92+
it('Check if element can be found by tag name', async function () {
9493
let driver = await new Builder().forBrowser('chrome').build();
9594
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
96-
const element = await driver.findElement(By.linkText("Selenium Official Page"));
95+
const element = await driver.findElement(By.tagName("a"));
9796

9897
const tag = await element.getTagName();
99-
const href = await element.getAttribute("href");
98+
const text = await element.getText();
10099

101100
assert.equal(tag, "a");
102-
assert.equal(href, "https://www.selenium.dev/");
101+
assert.equal(text, "Selenium Official Page");
103102
await driver.quit();
104103
});
105104

106-
it('Check if element can be found by partial link text', async function () {
105+
it('Check if element can be found by xpath', async function () {
107106
let driver = await new Builder().forBrowser('chrome').build();
108107
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
109-
const element = await driver.findElement(By.partialLinkText("Official Page"));
108+
const element = await driver.findElement(By.xpath('//input[@value="f"]'));
110109

111110
const tag = await element.getTagName();
112-
const href = await element.getAttribute("href");
111+
const type = await element.getAttribute("type");
112+
const value = await element.getAttribute("value");
113113

114-
assert.equal(tag, "a");
115-
assert.equal(href, "https://www.selenium.dev/");
114+
assert.equal(tag, "input");
115+
assert.equal(type, "radio");
116+
assert.equal(value, "f");
116117
await driver.quit();
117118
});
118119
});

website_and_docs/content/documentation/webdriver/elements/locators.en.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ textbox, using css.
123123
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L11" >}}
124124
{{< /tab >}}
125125
{{< tab header="JavaScript" >}}
126-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L21-L23" >}}
126+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L20-L22" >}}
127127
{{< /tab >}}
128128
{{< tab header="Kotlin" >}}
129129
val driver = ChromeDriver()
@@ -153,7 +153,7 @@ We will identify the Last Name field using it.
153153
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L15" >}}
154154
{{< /tab >}}
155155
{{< tab header="JavaScript" >}}
156-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L36-L38" >}}
156+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L35-L37" >}}
157157
{{< /tab >}}
158158
{{< tab header="Kotlin" >}}
159159
val driver = ChromeDriver()
@@ -184,7 +184,7 @@ We will identify the Newsletter checkbox using it.
184184
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L19" >}}
185185
{{< /tab >}}
186186
{{< tab header="JavaScript" >}}
187-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L51-L53" >}}
187+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L50-L52" >}}
188188
{{< /tab >}}
189189
{{< tab header="Kotlin" >}}
190190
val driver = ChromeDriver()
@@ -213,7 +213,7 @@ In the HTML snippet shared, we have a link available, let's see how will we loca
213213
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L23" >}}
214214
{{< /tab >}}
215215
{{< tab header="JavaScript" >}}
216-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L94-L96" >}}
216+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L67-L69" >}}
217217
{{< /tab >}}
218218
{{< tab header="Kotlin" >}}
219219
val driver = ChromeDriver()
@@ -243,7 +243,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
243243
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L27" >}}
244244
{{< /tab >}}
245245
{{< tab header="JavaScript" >}}
246-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L106-L108" >}}
246+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L80-L82" >}}
247247
{{< /tab >}}
248248
{{< tab header="Kotlin" >}}
249249
val driver = ChromeDriver()
@@ -271,7 +271,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
271271
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L31" >}}
272272
{{< /tab >}}
273273
{{< tab header="JavaScript" >}}
274-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L81-L83" >}}
274+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L93-L95" >}}
275275
{{< /tab >}}
276276
{{< tab header="Kotlin" >}}
277277
val driver = ChromeDriver()
@@ -305,7 +305,7 @@ first name text box. Let us create locator for female radio button using xpath.
305305
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L35" >}}
306306
{{< /tab >}}
307307
{{< tab header="JavaScript" >}}
308-
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L66-L68" >}}
308+
{{< gh-codeblock path="examples/javascript/test/elements/locators.spec.js#L106-L108" >}}
309309
{{< /tab >}}
310310
{{< tab header="Kotlin" >}}
311311
import org.openqa.selenium.By

0 commit comments

Comments
 (0)