Skip to content

Commit 4194a2f

Browse files
committed
remove html file and reference html from selenium.dev/selenium/web
1 parent f602128 commit 4194a2f

File tree

7 files changed

+77
-97
lines changed

7 files changed

+77
-97
lines changed

examples/python/tests/conftest.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from urllib.request import urlopen
1010
import requests
1111
from requests.auth import HTTPBasicAuth
12-
from http.server import HTTPServer, SimpleHTTPRequestHandler
13-
from threading import Thread
1412

1513
import pytest
1614
from selenium import webdriver
@@ -190,24 +188,6 @@ def wait_for_server(url, timeout):
190188
print("Selenium server has been terminated")
191189

192190

193-
@pytest.fixture(scope="session")
194-
def html_server():
195-
"""
196-
Start an HTTP server to serve files from the `tests/` directory.
197-
"""
198-
elements_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
199-
os.chdir(elements_dir)
200-
port = free_port()
201-
server = HTTPServer(("localhost", port), SimpleHTTPRequestHandler)
202-
203-
thread = Thread(target=server.serve_forever, daemon=True)
204-
thread.start()
205-
206-
yield f"http://localhost:{port}"
207-
208-
server.shutdown()
209-
210-
211191
@pytest.fixture(scope="function")
212192
def server():
213193
_host = "localhost"

examples/python/tests/elements/locators.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/python/tests/elements/test_locators.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,83 @@
22
from selenium import webdriver
33
from selenium.webdriver.common.by import By
44

5-
@pytest.fixture
6-
def driver(html_server):
7-
"""
8-
Initialize the WebDriver and navigate to the elements/locators.html page.
9-
"""
10-
driver = webdriver.Chrome()
11-
driver.implicitly_wait(0.5)
12-
driver.get(f"{html_server}/elements/locators.html")
13-
yield driver
14-
driver.quit()
155

16-
def test_class_name(driver):
6+
def test_class_name():
7+
driver = webdriver.Chrome()
8+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
179
element = driver.find_element(By.CLASS_NAME, "information")
10+
1811
assert element is not None
1912
assert element.tag_name == "input"
2013

14+
driver.quit()
15+
2116
def test_css_selector(driver):
17+
driver = webdriver.Chrome()
18+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
2219
element = driver.find_element(By.CSS_SELECTOR, "#fname")
20+
2321
assert element is not None
2422
assert element.get_attribute("value") == "Jane"
2523

24+
driver.quit()
25+
2626
def test_id(driver):
27+
driver = webdriver.Chrome()
28+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
2729
element = driver.find_element(By.ID, "lname")
30+
2831
assert element is not None
2932
assert element.get_attribute("value") == "Doe"
3033

34+
driver.quit()
35+
3136
def test_name(driver):
37+
driver = webdriver.Chrome()
38+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
3239
element = driver.find_element(By.NAME, "newsletter")
40+
3341
assert element is not None
3442
assert element.tag_name == "input"
3543

44+
driver.quit()
45+
3646
def test_link_text(driver):
47+
driver = webdriver.Chrome()
48+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
3749
element = driver.find_element(By.LINK_TEXT, "Selenium Official Page")
50+
3851
assert element is not None
3952
assert element.get_attribute("href") == "https://www.selenium.dev/"
4053

54+
driver.quit()
55+
4156
def test_partial_link_text(driver):
57+
driver = webdriver.Chrome()
58+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
4259
element = driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page")
60+
4361
assert element is not None
4462
assert element.get_attribute("href") == "https://www.selenium.dev/"
4563

64+
driver.quit()
65+
4666
def test_tag_name(driver):
67+
driver = webdriver.Chrome()
68+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
4769
element = driver.find_element(By.TAG_NAME, "a")
70+
4871
assert element is not None
4972
assert element.get_attribute("href") == "https://www.selenium.dev/"
5073

74+
driver.quit()
75+
5176
def test_xpath(driver):
77+
driver = webdriver.Chrome()
78+
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
5279
element = driver.find_element(By.XPATH, "//input[@value='f']")
80+
5381
assert element is not None
5482
assert element.get_attribute("type") == "radio"
83+
84+
driver.quit()

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ page. To understand and create locator we will use the following HTML snippet.
4949
</style>
5050
<h2>Contact Selenium</h2>
5151

52-
<form action="/action_page.php">
52+
<form>
5353
<input type="radio" name="gender" value="m" />Male &nbsp;
5454
<input type="radio" name="gender" value="f" />Female <br>
5555
<br>
@@ -81,7 +81,7 @@ available in Selenium.
8181
driver.findElement(By.className("information"));
8282
{{< /tab >}}
8383
{{< tab header="Python" text=true >}}
84-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L17" >}}
84+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L7-L9" >}}
8585
{{< /tab >}}
8686
{{< tab header="CSharp" >}}
8787
var driver = new ChromeDriver();
@@ -114,7 +114,7 @@ textbox, using css.
114114
driver.findElement(By.cssSelector("#fname"));
115115
{{< /tab >}}
116116
{{< tab header="Python" text=true >}}
117-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L22" >}}
117+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L17-L19" >}}
118118
{{< /tab >}}
119119
{{< tab header="CSharp" >}}
120120
var driver = new ChromeDriver();
@@ -145,7 +145,7 @@ We will identify the Last Name field using it.
145145
driver.findElement(By.id("lname"));
146146
{{< /tab >}}
147147
{{< tab header="Python" text=true >}}
148-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L27" >}}
148+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L27-L29" >}}
149149
{{< /tab >}}
150150
{{< tab header="CSharp" >}}
151151
var driver = new ChromeDriver();
@@ -177,7 +177,7 @@ We will identify the Newsletter checkbox using it.
177177
driver.findElement(By.name("newsletter"));
178178
{{< /tab >}}
179179
{{< tab header="Python" text=true >}}
180-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L32" >}}
180+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L37-L39" >}}
181181
{{< /tab >}}
182182
{{< tab header="CSharp" >}}
183183
var driver = new ChromeDriver();
@@ -207,7 +207,7 @@ In the HTML snippet shared, we have a link available, let's see how will we loca
207207
driver.findElement(By.linkText("Selenium Official Page"));
208208
{{< /tab >}}
209209
{{< tab header="Python" text=true >}}
210-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L37" >}}
210+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L47-L49" >}}
211211
{{< /tab >}}
212212
{{< tab header="CSharp" >}}
213213
var driver = new ChromeDriver();
@@ -238,7 +238,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
238238
driver.findElement(By.partialLinkText("Official Page"));
239239
{{< /tab >}}
240240
{{< tab header="Python" text=true >}}
241-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L42" >}}
241+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L57-L59" >}}
242242
{{< /tab >}}
243243
{{< tab header="CSharp" >}}
244244
var driver = new ChromeDriver();
@@ -267,7 +267,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
267267
driver.findElement(By.tagName("a"));
268268
{{< /tab >}}
269269
{{< tab header="Python" text=true >}}
270-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L47" >}}
270+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L67-L69" >}}
271271
{{< /tab >}}
272272
{{< tab header="CSharp" >}}
273273
var driver = new ChromeDriver();
@@ -302,7 +302,7 @@ first name text box. Let us create locator for female radio button using xpath.
302302
driver.findElement(By.xpath("//input[@value='f']"));
303303
{{< /tab >}}
304304
{{< tab header="Python" text=true >}}
305-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L52" >}}
305+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L77-L79" >}}
306306
{{< /tab >}}
307307
{{< tab header="CSharp" >}}
308308
var driver = new ChromeDriver();

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ page. To understand and create locator we will use the following HTML snippet.
4848
</style>
4949
<h2>Contact Selenium</h2>
5050

51-
<form action="/action_page.php">
51+
<form>
5252
<input type="radio" name="gender" value="m" />Male &nbsp;
5353
<input type="radio" name="gender" value="f" />Female <br>
5454
<br>
@@ -79,7 +79,7 @@ available in Selenium.
7979
driver.findElement(By.className("information"));
8080
{{< /tab >}}
8181
{{< tab header="Python" text=true >}}
82-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L17" >}}
82+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L7-L9" >}}
8383
{{< /tab >}}
8484
{{< tab header="CSharp" >}}
8585
var driver = new ChromeDriver();
@@ -111,7 +111,7 @@ textbox, using css.
111111
driver.findElement(By.cssSelector("#fname"));
112112
{{< /tab >}}
113113
{{< tab header="Python" text=true >}}
114-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L22" >}}
114+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L17-L19" >}}
115115
{{< /tab >}}
116116
{{< tab header="CSharp" >}}
117117
var driver = new ChromeDriver();
@@ -141,7 +141,7 @@ We will identify the Last Name field using it.
141141
driver.findElement(By.id("lname"));
142142
{{< /tab >}}
143143
{{< tab header="Python" text=true >}}
144-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L27" >}}
144+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L27-L29" >}}
145145
{{< /tab >}}
146146
{{< tab header="CSharp" >}}
147147
var driver = new ChromeDriver();
@@ -172,7 +172,7 @@ We will identify the Newsletter checkbox using it.
172172
driver.findElement(By.name("newsletter"));
173173
{{< /tab >}}
174174
{{< tab header="Python" text=true >}}
175-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L32" >}}
175+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L37-L39" >}}
176176
{{< /tab >}}
177177
{{< tab header="CSharp" >}}
178178
var driver = new ChromeDriver();
@@ -201,7 +201,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
201201
driver.findElement(By.linkText("Selenium Official Page"));
202202
{{< /tab >}}
203203
{{< tab header="Python" text=true >}}
204-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L37" >}}
204+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L47-L49" >}}
205205
{{< /tab >}}
206206
{{< tab header="CSharp" >}}
207207
var driver = new ChromeDriver();
@@ -231,7 +231,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
231231
driver.findElement(By.partialLinkText("Official Page"));
232232
{{< /tab >}}
233233
{{< tab header="Python" text=true >}}
234-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L42" >}}
234+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L57-L59" >}}
235235
{{< /tab >}}
236236
{{< tab header="CSharp" >}}
237237
var driver = new ChromeDriver();
@@ -259,7 +259,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
259259
driver.findElement(By.tagName("a"));
260260
{{< /tab >}}
261261
{{< tab header="Python" text=true >}}
262-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L47" >}}
262+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L67-L69" >}}
263263
{{< /tab >}}
264264
{{< tab header="CSharp" >}}
265265
var driver = new ChromeDriver();
@@ -293,7 +293,7 @@ first name text box. Let us create locator for female radio button using xpath.
293293
driver.findElement(By.xpath("//input[@value='f']"));
294294
{{< /tab >}}
295295
{{< tab header="Python" text=true >}}
296-
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L52" >}}
296+
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L77-L79" >}}
297297
{{< /tab >}}
298298
{{< tab header="CSharp" >}}
299299
var driver = new ChromeDriver();

0 commit comments

Comments
 (0)