Skip to content

Commit 34cc4d9

Browse files
authored
[py] move interactions code to code examples (SeleniumHQ#2085)
1 parent 2c917d8 commit 34cc4d9

File tree

5 files changed

+49
-104
lines changed

5 files changed

+49
-104
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
11
from selenium import webdriver
2+
from selenium.webdriver.common.by import By
23

4+
import pytest
5+
6+
7+
def test_interactions():
8+
# Initialize WebDriver
9+
driver = webdriver.Chrome()
10+
driver.implicitly_wait(0.5)
11+
12+
# Navigate to URL
13+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
14+
15+
# Click on the checkbox
16+
check_input = driver.find_element(By.NAME, "checkbox_input")
17+
check_input.click()
18+
19+
is_checked = check_input.is_selected()
20+
assert is_checked == False
21+
22+
# Handle the email input field
23+
email_input = driver.find_element(By.NAME, "email_input")
24+
email_input.clear() # Clear field
25+
26+
27+
email_input.send_keys(email) # Enter text
28+
29+
# Verify input
30+
data = email_input.get_attribute("value")
31+
assert data == email
32+
33+
# Clear the email input field again
34+
email_input.clear()
35+
data = email_input.get_attribute("value")
36+
assert data == ""
37+
38+
# Quit the driver
39+
driver.quit()

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

+3-26
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ Selenium will return an [element click intercepted](https://w3c.github.io/webdri
4949
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}}
5050
{{< /tab >}}
5151
{{< tab header="Python" >}}
52-
53-
# Navigate to url
54-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
55-
56-
# Click on the element
57-
driver.find_element(By.NAME, "color_input").click()
52+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}}
5853
{{< /tab >}}
5954

6055
{{< tab header="CSharp" text=true >}}
@@ -95,17 +90,7 @@ possible keystrokes that WebDriver Supports.
9590
{{< /tab >}}
9691

9792
{{< tab header="Python" >}}
98-
99-
100-
# Navigate to url
101-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
102-
103-
# Clear field to empty it from any previous data
104-
driver.find_element(By.NAME, "email_input").clear()
105-
106-
# Enter Text
107-
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" )
108-
93+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}}
10994
{{< /tab >}}
11095

11196
{{< tab header="CSharp" text=true >}}
@@ -147,15 +132,7 @@ with a`content-editable` attribute. If these conditions are not met,
147132
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}}
148133
{{< /tab >}}
149134
{{< tab header="Python" >}}
150-
151-
152-
# Navigate to url
153-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
154-
155-
# Clear field to empty it from any previous data
156-
driver.find_element(By.NAME, "email_input").clear()
157-
158-
135+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}}
159136
{{< /tab >}}
160137

161138

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

+3-26
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ Selenium will return an [element click intercepted](https://w3c.github.io/webdri
4545
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}}
4646
{{< /tab >}}
4747
{{< tab header="Python" >}}
48-
49-
# Navigate to url
50-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
51-
52-
# Click on the element
53-
driver.find_element(By.NAME, "color_input").click()
48+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}}
5449
{{< /tab >}}
5550

5651
{{< tab header="CSharp" text=true >}}
@@ -92,17 +87,7 @@ possible keystrokes that WebDriver Supports.
9287
{{< /tab >}}
9388

9489
{{< tab header="Python" >}}
95-
96-
97-
# Navigate to url
98-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
99-
100-
# Clear field to empty it from any previous data
101-
driver.find_element(By.NAME, "email_input").clear()
102-
103-
# Enter Text
104-
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" )
105-
90+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}}
10691
{{< /tab >}}
10792

10893
{{< tab header="CSharp" text=true >}}
@@ -143,15 +128,7 @@ with a`content-editable` attribute. If these conditions are not met,
143128
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}}
144129
{{< /tab >}}
145130
{{< tab header="Python" >}}
146-
147-
148-
# Navigate to url
149-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
150-
151-
# Clear field to empty it from any previous data
152-
driver.find_element(By.NAME, "email_input").clear()
153-
154-
131+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}}
155132
{{< /tab >}}
156133

157134
{{< tab header="CSharp" text=true >}}

website_and_docs/content/documentation/webdriver/elements/interactions.pt-br.md

+3-26
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ Selenium will return an [element click intercepted](https://w3c.github.io/webdri
4646
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}}
4747
{{< /tab >}}
4848
{{< tab header="Python" >}}
49-
50-
# Navigate to url
51-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
52-
53-
# Click on the element
54-
driver.find_element(By.NAME, "color_input").click()
49+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}}
5550
{{< /tab >}}
5651

5752
{{< tab header="CSharp" text=true >}}
@@ -93,17 +88,7 @@ possible keystrokes that WebDriver Supports.
9388
{{< /tab >}}
9489

9590
{{< tab header="Python" >}}
96-
97-
98-
# Navigate to url
99-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
100-
101-
# Clear field to empty it from any previous data
102-
driver.find_element(By.NAME, "email_input").clear()
103-
104-
# Enter Text
105-
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" )
106-
91+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}}
10792
{{< /tab >}}
10893

10994
{{< tab header="CSharp" text=true >}}
@@ -144,15 +129,7 @@ with a`content-editable` attribute. If these conditions are not met,
144129
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}}
145130
{{< /tab >}}
146131
{{< tab header="Python" >}}
147-
148-
149-
# Navigate to url
150-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
151-
152-
# Clear field to empty it from any previous data
153-
driver.find_element(By.NAME, "email_input").clear()
154-
155-
132+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}}
156133
{{< /tab >}}
157134

158135
{{< tab header="CSharp" text=true >}}

website_and_docs/content/documentation/webdriver/elements/interactions.zh-cn.md

+3-26
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#df
4848
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}}
4949
{{< /tab >}}
5050
{{< tab header="Python" >}}
51-
52-
# Navigate to url
53-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
54-
55-
# Click on the element
56-
driver.find_element(By.NAME, "color_input").click()
51+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}}
5752
{{< /tab >}}
5853

5954
{{< tab header="CSharp" text=true >}}
@@ -95,17 +90,7 @@ Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#df
9590
{{< /tab >}}
9691

9792
{{< tab header="Python" >}}
98-
99-
100-
# Navigate to url
101-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
102-
103-
# Clear field to empty it from any previous data
104-
driver.find_element(By.NAME, "email_input").clear()
105-
106-
# Enter Text
107-
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" )
108-
93+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}}
10994
{{< /tab >}}
11095

11196
{{< tab header="CSharp" text=true >}}
@@ -148,15 +133,7 @@ Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#df
148133
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}}
149134
{{< /tab >}}
150135
{{< tab header="Python" >}}
151-
152-
153-
# Navigate to url
154-
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
155-
156-
# Clear field to empty it from any previous data
157-
driver.find_element(By.NAME, "email_input").clear()
158-
159-
136+
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}}
160137
{{< /tab >}}
161138

162139
{{< tab header="CSharp" text=true >}}

0 commit comments

Comments
 (0)