-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[py] move interactions code to code examples (#2085)
- Loading branch information
Showing
5 changed files
with
49 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.common.by import By | ||
|
||
import pytest | ||
|
||
|
||
def test_interactions(): | ||
# Initialize WebDriver | ||
driver = webdriver.Chrome() | ||
driver.implicitly_wait(0.5) | ||
|
||
# Navigate to URL | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Click on the checkbox | ||
check_input = driver.find_element(By.NAME, "checkbox_input") | ||
check_input.click() | ||
|
||
is_checked = check_input.is_selected() | ||
assert is_checked == False | ||
|
||
# Handle the email input field | ||
email_input = driver.find_element(By.NAME, "email_input") | ||
email_input.clear() # Clear field | ||
|
||
email = "[email protected]" | ||
email_input.send_keys(email) # Enter text | ||
|
||
# Verify input | ||
data = email_input.get_attribute("value") | ||
assert data == email | ||
|
||
# Clear the email input field again | ||
email_input.clear() | ||
data = email_input.get_attribute("value") | ||
assert data == "" | ||
|
||
# Quit the driver | ||
driver.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,12 +49,7 @@ Selenium will return an [element click intercepted](https://w3c.github.io/webdri | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Click on the element | ||
driver.find_element(By.NAME, "color_input").click() | ||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -95,17 +90,7 @@ possible keystrokes that WebDriver Supports. | |
{{< /tab >}} | ||
|
||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
# Enter Text | ||
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" ) | ||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -147,15 +132,7 @@ with a`content-editable` attribute. If these conditions are not met, | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}} | ||
{{< /tab >}} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,12 +45,7 @@ Selenium will return an [element click intercepted](https://w3c.github.io/webdri | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Click on the element | ||
driver.find_element(By.NAME, "color_input").click() | ||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -92,17 +87,7 @@ possible keystrokes that WebDriver Supports. | |
{{< /tab >}} | ||
|
||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
# Enter Text | ||
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" ) | ||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -143,15 +128,7 @@ with a`content-editable` attribute. If these conditions are not met, | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,12 +46,7 @@ Selenium will return an [element click intercepted](https://w3c.github.io/webdri | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Click on the element | ||
driver.find_element(By.NAME, "color_input").click() | ||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -93,17 +88,7 @@ possible keystrokes that WebDriver Supports. | |
{{< /tab >}} | ||
|
||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
# Enter Text | ||
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" ) | ||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -144,15 +129,7 @@ with a`content-editable` attribute. If these conditions are not met, | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,12 +48,7 @@ Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#df | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L18-L22" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Click on the element | ||
driver.find_element(By.NAME, "color_input").click() | ||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L12-L17" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -95,17 +90,7 @@ Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#df | |
{{< /tab >}} | ||
|
||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
# Enter Text | ||
driver.find_element(By.NAME, "email_input").send_keys("[email protected]" ) | ||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L22-L27" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|
@@ -148,15 +133,7 @@ Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#df | |
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/InteractionTest.java#L38-L40" >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
|
||
|
||
# Navigate to url | ||
driver.get("https://www.selenium.dev/selenium/web/inputs.html") | ||
|
||
# Clear field to empty it from any previous data | ||
driver.find_element(By.NAME, "email_input").clear() | ||
|
||
|
||
{{< gh-codeblock path="examples/python/tests/elements/test_interaction.py#L34" >}} | ||
{{< /tab >}} | ||
|
||
{{< tab header="CSharp" text=true >}} | ||
|