-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Update elements finders python docs #2099
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
Open
pmartinez1
wants to merge
4
commits into
SeleniumHQ:trunk
from
pmartinez1:update-elements-finders-python-docs
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d2f612e
Add code that is to be used in examples
pmartinez1 fee6557
Updates to moving code for python Finders docs
pmartinez1 9e87d2c
Merge branch 'trunk' into update-elements-finders-python-docs
diemol d025197
Merge branch 'trunk' into update-elements-finders-python-docs
diemol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
examples/python/tests/elements/test_finders.py
This file contains hidden or 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,93 @@ | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.by import By | ||
|
|
||
|
|
||
| def test_basic_finders(): | ||
| driver = webdriver.Chrome() | ||
| driver.get('https://www.selenium.dev/') | ||
|
|
||
| body_on_page = driver.find_element(By.CLASS_NAME, 'td-home') | ||
| container_on_page = body_on_page.find_element(By.CLASS_NAME, 'container-fluid') | ||
|
|
||
| assert container_on_page.is_displayed() | ||
|
|
||
| driver.quit() | ||
|
|
||
| def test_evaluating_shadow_DOM(): | ||
| driver = webdriver.Chrome() | ||
| driver.implicitly_wait(5) | ||
| driver.get('https://www.selenium.dev/selenium/web/shadowRootPage.html') | ||
|
|
||
| custom_element = driver.find_element(By.TAG_NAME, 'custom-checkbox-element') | ||
| shadow_dom_input = custom_element.shadow_root.find_element(By.CSS_SELECTOR, 'input[type=checkbox]') | ||
|
|
||
| assert custom_element.is_displayed() | ||
| assert custom_element.shadow_root | ||
| assert shadow_dom_input.is_displayed() | ||
|
|
||
| driver.quit() | ||
|
|
||
| def test_optimized_locator(): | ||
| driver = webdriver.Chrome() | ||
| driver.get('https://www.selenium.dev/') | ||
|
|
||
| nested_element = driver.find_element(By.CSS_SELECTOR, '.td-home #announcement-banner') | ||
|
|
||
| assert nested_element.is_displayed() | ||
|
|
||
| driver.quit() | ||
|
|
||
| def test_all_matching_elements(): | ||
| driver = webdriver.Chrome() | ||
| driver.get('https://www.selenium.dev/') | ||
|
|
||
| header_two_elements = driver.find_elements(By.TAG_NAME, 'h2') | ||
|
|
||
| assert len(header_two_elements) > 1 | ||
|
|
||
| for header_element in header_two_elements: | ||
| print(header_element.text) | ||
|
|
||
| driver.quit() | ||
|
|
||
| def test_find_elements_from_element(): | ||
| driver = webdriver.Chrome() | ||
| driver.get('https://www.selenium.dev/') | ||
|
|
||
| main_element = driver.find_element(By.TAG_NAME, 'main') | ||
| svg_elements = main_element.find_elements(By.TAG_NAME, 'svg') | ||
|
|
||
| for svg_element in svg_elements: | ||
| print(svg_element.is_displayed()) | ||
|
|
||
| ## get elements from parent element using XPATH | ||
| ## NOTE: in order to utilize XPATH from current element, you must add "." to beginning of path | ||
|
|
||
| header_tag = driver.find_element(By.TAG_NAME, 'header') | ||
| # Get first element of tag 'ul' | ||
| ul_tag = header_tag.find_element(By.XPATH, '//ul') | ||
|
|
||
| # get children of tag 'ul' with tag 'li' | ||
| elements = ul_tag.find_elements(By.XPATH, './/li') | ||
|
|
||
| for element in elements: | ||
| print(element.text) | ||
|
|
||
| assert len(elements) > 0 | ||
| assert len(svg_elements) > 1 | ||
|
|
||
| driver.quit() | ||
|
|
||
| def test_get_active_element(): | ||
| driver = webdriver.Chrome() | ||
| driver.get('https://www.selenium.dev/') | ||
|
|
||
| dropdown = driver.find_element(By.CSS_SELECTOR, '.nav-item.dropdown') | ||
| dropdown.click() | ||
|
|
||
| active_element = driver.switch_to.active_element | ||
|
|
||
| assert active_element.get_attribute('href').endswith('#') | ||
|
|
||
| driver.quit() | ||
|
|
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.