Skip to content

Commit

Permalink
[py] move interactions code to code examples (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 authored Nov 29, 2024
1 parent 2c917d8 commit 34cc4d9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 104 deletions.
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

0 comments on commit 34cc4d9

Please sign in to comment.