Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py] move interactions code to code examples #2085

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/python/tests/elements/test_interaction.py
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()
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down
Loading