Skip to content

Commit b31c564

Browse files
committed
check commit
1 parent 66b3050 commit b31c564

File tree

2 files changed

+126
-16
lines changed

2 files changed

+126
-16
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
const {By, Builder} = require('selenium-webdriver');
2+
const assert = require("assert");
3+
4+
describe('Element Locator Test', function () {
5+
it('Check if element can be found by class name', async () => {
6+
let driver = await new Builder().forBrowser('chrome').build();
7+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
8+
const element = await driver.findElement(By.className('information'));
9+
10+
const tag = await element.getTagName();
11+
const id = await element.getAttribute("id");
12+
const value = await element.getAttribute("value");
13+
14+
assert.equal(tag, "input");
15+
assert.equal(id, "fname");
16+
assert.equal(value, "Jane");
17+
await driver.quit();
18+
});
19+
20+
it('Check if element can be found by css selector', async function () {
21+
let driver = await new Builder().forBrowser('chrome').build();
22+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
23+
const element = await driver.findElement(By.css('#fname'));
24+
25+
const tag = await element.getTagName();
26+
const id = await element.getAttribute("id");
27+
const value = await element.getAttribute("value");
28+
29+
assert.equal(tag, "input");
30+
assert.equal(id, "fname");
31+
assert.equal(value, "Jane");
32+
await driver.quit();
33+
});
34+
35+
it('Check if element can be found by id', async function () {
36+
let driver = await new Builder().forBrowser('chrome').build();
37+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
38+
const element = await driver.findElement(By.id('lname'));
39+
40+
const tag = await element.getTagName();
41+
const id = await element.getAttribute("id");
42+
const value = await element.getAttribute("value");
43+
44+
assert.equal(tag, "input");
45+
assert.equal(id, "lname");
46+
assert.equal(value, "Doe");
47+
await driver.quit();
48+
});
49+
50+
it('Check if element can be found by name', async function () {
51+
let driver = await new Builder().forBrowser('chrome').build();
52+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
53+
const element = await driver.findElement(By.name("gender"));
54+
55+
const tag = await element.getTagName();
56+
const type = await element.getAttribute("type");
57+
const value = await element.getAttribute("value");
58+
59+
assert.equal(tag, "input");
60+
assert.equal(type, "radio");
61+
assert.equal(value, "m");
62+
await driver.quit();
63+
});
64+
65+
it('Check if element can be found by xpath', async function () {
66+
let driver = await new Builder().forBrowser('chrome').build();
67+
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+
70+
const tag = await element.getTagName();
71+
const type = await element.getAttribute("type");
72+
const value = await element.getAttribute("value");
73+
74+
assert.equal(tag, "input");
75+
assert.equal(type, "checkbox");
76+
assert.equal(value, "1");
77+
await driver.quit();
78+
});
79+
80+
it('Check if element can be found by tag name', async function () {
81+
let driver = await new Builder().forBrowser('chrome').build();
82+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
83+
const element = await driver.findElement(By.tagName("h2"));
84+
85+
const tag = await element.getTagName();
86+
const text = await element.getText();
87+
88+
assert.equal(tag, "h2");
89+
assert.equal(text, "Contact Selenium");
90+
await driver.quit();
91+
});
92+
93+
it('Check if element can be found by link text', async function () {
94+
let driver = await new Builder().forBrowser('chrome').build();
95+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
96+
const element = await driver.findElement(By.linkText("Selenium Official Page"));
97+
98+
const tag = await element.getTagName();
99+
const href = await element.getAttribute("href");
100+
101+
assert.equal(tag, "a");
102+
assert.equal(href, "https://www.selenium.dev/");
103+
await driver.quit();
104+
});
105+
106+
it('Check if element can be found by partial link text', async function () {
107+
let driver = await new Builder().forBrowser('chrome').build();
108+
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
109+
const element = await driver.findElement(By.partialLinkText("Official Page"));
110+
111+
const tag = await element.getTagName();
112+
const href = await element.getAttribute("href");
113+
114+
assert.equal(tag, "a");
115+
assert.equal(href, "https://www.selenium.dev/");
116+
await driver.quit();
117+
});
118+
});

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ available in Selenium.
9191
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L7" >}}
9292
{{< /tab >}}
9393
{{< tab header="JavaScript" >}}
94-
let driver = await new Builder().forBrowser('chrome').build();
95-
const loc = await driver.findElement(By.className('information'));
94+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L6-L8" >}}
9695
{{< /tab >}}
9796
{{< tab header="Kotlin" >}}
9897
val driver = ChromeDriver()
@@ -124,8 +123,7 @@ textbox, using css.
124123
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L11" >}}
125124
{{< /tab >}}
126125
{{< tab header="JavaScript" >}}
127-
let driver = await new Builder().forBrowser('chrome').build();
128-
const loc = await driver.findElement(By.css('#fname'));
126+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L21-L23" >}}
129127
{{< /tab >}}
130128
{{< tab header="Kotlin" >}}
131129
val driver = ChromeDriver()
@@ -155,8 +153,7 @@ We will identify the Last Name field using it.
155153
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L15" >}}
156154
{{< /tab >}}
157155
{{< tab header="JavaScript" >}}
158-
let driver = await new Builder().forBrowser('chrome').build();
159-
const loc = await driver.findElement(By.id('lname'));
156+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L36-L38" >}}
160157
{{< /tab >}}
161158
{{< tab header="Kotlin" >}}
162159
val driver = ChromeDriver()
@@ -187,8 +184,7 @@ We will identify the Newsletter checkbox using it.
187184
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L19" >}}
188185
{{< /tab >}}
189186
{{< tab header="JavaScript" >}}
190-
let driver = await new Builder().forBrowser('chrome').build();
191-
const loc = await driver.findElement(By.name('newsletter'));
187+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L51-L53" >}}
192188
{{< /tab >}}
193189
{{< tab header="Kotlin" >}}
194190
val driver = ChromeDriver()
@@ -217,8 +213,7 @@ In the HTML snippet shared, we have a link available, let's see how will we loca
217213
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L23" >}}
218214
{{< /tab >}}
219215
{{< tab header="JavaScript" >}}
220-
let driver = await new Builder().forBrowser('chrome').build();
221-
const loc = await driver.findElement(By.linkText('Selenium Official Page'));
216+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L94-L96" >}}
222217
{{< /tab >}}
223218
{{< tab header="Kotlin" >}}
224219
val driver = ChromeDriver()
@@ -248,8 +243,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
248243
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L27" >}}
249244
{{< /tab >}}
250245
{{< tab header="JavaScript" >}}
251-
let driver = await new Builder().forBrowser('chrome').build();
252-
const loc = await driver.findElement(By.partialLinkText('Official Page'));
246+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L106-L108" >}}
253247
{{< /tab >}}
254248
{{< tab header="Kotlin" >}}
255249
val driver = ChromeDriver()
@@ -277,8 +271,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
277271
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L31" >}}
278272
{{< /tab >}}
279273
{{< tab header="JavaScript" >}}
280-
let driver = await new Builder().forBrowser('chrome').build();
281-
const loc = await driver.findElement(By.tagName('a'));
274+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L81-L83" >}}
282275
{{< /tab >}}
283276
{{< tab header="Kotlin" >}}
284277
val driver = ChromeDriver()
@@ -312,8 +305,7 @@ first name text box. Let us create locator for female radio button using xpath.
312305
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L35" >}}
313306
{{< /tab >}}
314307
{{< tab header="JavaScript" >}}
315-
let driver = await new Builder().forBrowser('chrome').build();
316-
const loc = await driver.findElement(By.xpath('//input[@value='f']'));
308+
{{< gh-codeblock path="/examples/javascript/test/elements/locators.spec.js#L66-L68" >}}
317309
{{< /tab >}}
318310
{{< tab header="Kotlin" >}}
319311
import org.openqa.selenium.By

0 commit comments

Comments
 (0)