Skip to content

Commit

Permalink
Merge branch 'trunk' into csharp-selenium-manager-example
Browse files Browse the repository at this point in the history
  • Loading branch information
shbenzer authored Dec 30, 2024
2 parents fc29eff + de1b1b5 commit 35250fd
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 170 deletions.
12 changes: 6 additions & 6 deletions examples/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
selenium==4.27.1
pytest
trio
pytest-trio
pytest-rerunfailures
flake8
requests
pytest==8.3.4
trio==0.27.0
pytest-trio==0.8.0
pytest-rerunfailures==14.0
flake8==7.1.1
requests==2.32.3
82 changes: 82 additions & 0 deletions examples/python/tests/elements/test_locators.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,84 @@
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By


def test_class_name():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.CLASS_NAME, "information")

assert element is not None
assert element.tag_name == "input"

driver.quit()

def test_css_selector(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.CSS_SELECTOR, "#fname")

assert element is not None
assert element.get_attribute("value") == "Jane"

driver.quit()

def test_id(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.ID, "lname")

assert element is not None
assert element.get_attribute("value") == "Doe"

driver.quit()

def test_name(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.NAME, "newsletter")

assert element is not None
assert element.tag_name == "input"

driver.quit()

def test_link_text(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.LINK_TEXT, "Selenium Official Page")

assert element is not None
assert element.get_attribute("href") == "https://www.selenium.dev/"

driver.quit()

def test_partial_link_text(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page")

assert element is not None
assert element.get_attribute("href") == "https://www.selenium.dev/"

driver.quit()

def test_tag_name(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.TAG_NAME, "a")

assert element is not None
assert element.get_attribute("href") == "https://www.selenium.dev/"

driver.quit()

def test_xpath(driver):
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html")
element = driver.find_element(By.XPATH, "//input[@value='f']")

assert element is not None
assert element.get_attribute("type") == "radio"

driver.quit()
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ page. To understand and create locator we will use the following HTML snippet.
</style>
<h2>Contact Selenium</h2>

<form action="/action_page.php">
<form>
<input type="radio" name="gender" value="m" />Male &nbsp;
<input type="radio" name="gender" value="f" />Female <br>
<br>
Expand Down Expand Up @@ -80,10 +80,9 @@ available in Selenium.
WebDriver driver = new ChromeDriver();
driver.findElement(By.className("information"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.CLASS_NAME, "information")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L7-L9" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.ClassName("information"));
Expand Down Expand Up @@ -114,10 +113,9 @@ textbox, using css.
WebDriver driver = new ChromeDriver();
driver.findElement(By.cssSelector("#fname"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.CSS_SELECTOR, "#fname")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L17-L19" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.CssSelector("#fname"));
Expand Down Expand Up @@ -146,10 +144,9 @@ We will identify the Last Name field using it.
WebDriver driver = new ChromeDriver();
driver.findElement(By.id("lname"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.ID, "lname")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L27-L29" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.Id("lname"));
Expand Down Expand Up @@ -179,10 +176,9 @@ We will identify the Newsletter checkbox using it.
WebDriver driver = new ChromeDriver();
driver.findElement(By.name("newsletter"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.NAME, "newsletter")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L37-L39" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.Name("newsletter"));
Expand Down Expand Up @@ -210,10 +206,9 @@ In the HTML snippet shared, we have a link available, let's see how will we loca
WebDriver driver = new ChromeDriver();
driver.findElement(By.linkText("Selenium Official Page"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.LINK_TEXT, "Selenium Official Page")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L47-L49" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.LinkText("Selenium Official Page"));
Expand Down Expand Up @@ -242,10 +237,9 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
WebDriver driver = new ChromeDriver();
driver.findElement(By.partialLinkText("Official Page"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L57-L59" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.PartialLinkText("Official Page"));
Expand All @@ -272,10 +266,9 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
WebDriver driver = new ChromeDriver();
driver.findElement(By.tagName("a"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.TAG_NAME, "a")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L67-L69" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.TagName("a"));
Expand Down Expand Up @@ -308,10 +301,9 @@ first name text box. Let us create locator for female radio button using xpath.
WebDriver driver = new ChromeDriver();
driver.findElement(By.xpath("//input[@value='f']"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.XPATH, "//input[@value='f']")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L77-L79" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.Xpath("//input[@value='f']"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ page. To understand and create locator we will use the following HTML snippet.
</style>
<h2>Contact Selenium</h2>

<form action="/action_page.php">
<form>
<input type="radio" name="gender" value="m" />Male &nbsp;
<input type="radio" name="gender" value="f" />Female <br>
<br>
Expand Down Expand Up @@ -78,10 +78,9 @@ available in Selenium.
WebDriver driver = new ChromeDriver();
driver.findElement(By.className("information"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.CLASS_NAME, "information")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L7-L9" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.ClassName("information"));
Expand Down Expand Up @@ -111,10 +110,9 @@ textbox, using css.
WebDriver driver = new ChromeDriver();
driver.findElement(By.cssSelector("#fname"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.CSS_SELECTOR, "#fname")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L17-L19" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.CssSelector("#fname"));
Expand Down Expand Up @@ -142,10 +140,9 @@ We will identify the Last Name field using it.
WebDriver driver = new ChromeDriver();
driver.findElement(By.id("lname"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.ID, "lname")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L27-L29" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.Id("lname"));
Expand Down Expand Up @@ -174,10 +171,9 @@ We will identify the Newsletter checkbox using it.
WebDriver driver = new ChromeDriver();
driver.findElement(By.name("newsletter"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.NAME, "newsletter")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L37-L39" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.Name("newsletter"));
Expand All @@ -204,10 +200,9 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
WebDriver driver = new ChromeDriver();
driver.findElement(By.linkText("Selenium Official Page"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.LINK_TEXT, "Selenium Official Page")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L47-L49" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.LinkText("Selenium Official Page"));
Expand Down Expand Up @@ -235,10 +230,9 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
WebDriver driver = new ChromeDriver();
driver.findElement(By.partialLinkText("Official Page"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L57-L59" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.PartialLinkText("Official Page"));
Expand All @@ -264,10 +258,9 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
WebDriver driver = new ChromeDriver();
driver.findElement(By.tagName("a"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.TAG_NAME, "a")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L67-L69" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.TagName("a"));
Expand Down Expand Up @@ -299,10 +292,9 @@ first name text box. Let us create locator for female radio button using xpath.
WebDriver driver = new ChromeDriver();
driver.findElement(By.xpath("//input[@value='f']"));
{{< /tab >}}
{{< tab header="Python" >}}
driver = webdriver.Chrome()
driver.find_element(By.XPATH, "//input[@value='f']")
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/elements/test_locators.py#L77-L79" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var driver = new ChromeDriver();
driver.FindElement(By.Xpath("//input[@value='f']"));
Expand Down
Loading

0 comments on commit 35250fd

Please sign in to comment.