Skip to content

Commit b600ca1

Browse files
committed
Practising with selectors
1 parent 79f95f6 commit b600ca1

11 files changed

+478
-12
lines changed

1-UI-Elements/geckodriver.log

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,3 +1697,44 @@ console.error: ({})
16971697
JavaScript warning: https://pagead2.googlesyndication.com/bg/eD-LbCVv8RN4elg6Wh2WeHuIVrik8zRjU-U-w0vCCto.js line 2 > eval line 1757 > eval line 1 > eval line 1 > eval, line 1: WEBGL_debug_renderer_info is deprecated in Firefox and will be removed. Please use RENDERER.
16981698
1715858031781 Marionette INFO Stopped listening on port 51696
16991699
Dynamically enable window occlusion 1
1700+
1716889463763 geckodriver INFO Listening on 127.0.0.1:56712
1701+
1716889466874 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "--remote-debugging-port" "56713" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "C:\\Users\\HP\\AppData\\Local\\Temp\\rust_mozprofileIoQ2bF"
1702+
console.warn: services.settings: Ignoring preference override of remote settings server
1703+
console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
1704+
Dynamically enable window occlusion 0
1705+
1716889467808 Marionette INFO Marionette enabled
1706+
1716889467915 Marionette INFO Listening on port 56724
1707+
WebDriver BiDi listening on ws://127.0.0.1:56713
1708+
Read port: 56724
1709+
1716889468182 RemoteAgent WARN TLS certificate errors will be ignored for this session
1710+
DevTools listening on ws://127.0.0.1:56713/devtools/browser/c33168ca-9f66-42cd-bd60-af948e1a3e3a
1711+
1716889477194 Marionette INFO Stopped listening on port 56724
1712+
Dynamically enable window occlusion 1
1713+
1716889523798 geckodriver INFO Listening on 127.0.0.1:56786
1714+
1716889526852 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "--remote-debugging-port" "56787" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "C:\\Users\\HP\\AppData\\Local\\Temp\\rust_mozprofilegDIoep"
1715+
console.warn: services.settings: Ignoring preference override of remote settings server
1716+
console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
1717+
Dynamically enable window occlusion 0
1718+
1716889527251 Marionette INFO Marionette enabled
1719+
1716889527332 Marionette INFO Listening on port 56795
1720+
WebDriver BiDi listening on ws://127.0.0.1:56787
1721+
Read port: 56795
1722+
1716889527546 RemoteAgent WARN TLS certificate errors will be ignored for this session
1723+
DevTools listening on ws://127.0.0.1:56787/devtools/browser/a290cd20-69a4-47fe-9fd4-f040fcf0b335
1724+
1716889535132 Marionette INFO Stopped listening on port 56795
1725+
Dynamically enable window occlusion 1
1726+
1716889597462 geckodriver INFO Listening on 127.0.0.1:56868
1727+
1716889600560 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "--remote-debugging-port" "56869" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "C:\\Users\\HP\\AppData\\Local\\Temp\\rust_mozprofileiLVz01"
1728+
console.warn: services.settings: Ignoring preference override of remote settings server
1729+
console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
1730+
Dynamically enable window occlusion 0
1731+
1716889600956 Marionette INFO Marionette enabled
1732+
1716889601036 Marionette INFO Listening on port 56877
1733+
WebDriver BiDi listening on ws://127.0.0.1:56869
1734+
Read port: 56877
1735+
1716889601252 RemoteAgent WARN TLS certificate errors will be ignored for this session
1736+
DevTools listening on ws://127.0.0.1:56869/devtools/browser/4b548047-adc0-4ba8-8360-1130a294ba59
1737+
console.warn: LoginRecipes: "Falling back to a synchronous message for: https://the-internet.herokuapp.com."
1738+
console.warn: LoginRecipes: "Falling back to a synchronous message for: https://the-internet.herokuapp.com."
1739+
1716889618298 Marionette INFO Stopped listening on port 56877
1740+
Dynamically enable window occlusion 1

1-UI-Elements/temp_test.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,4 @@
33

44
# Firefox webdriver for herokuapp site
55
fDriver = webdriver.Firefox()
6-
fDriver.get('https://the-internet.herokuapp.com/javascript_alerts')
7-
8-
fDriver.find_element(By.CSS_SELECTOR, "ul > li:nth-child(1) > button").click()
9-
10-
# Switch to alert
11-
popup = fDriver.switch_to.alert
12-
popup.accept()
13-
result = fDriver.find_element(By.ID, 'result').text
14-
assert result == 'You successfully clicked an alert'
15-
16-
17-
6+
fDriver.get('...')

Practice/find-element-by-classname.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Selecting elements by using Class Name
3+
- Combound classes are not allowed to use.
4+
- Classes are repeated so, their usage is not suggested.
5+
"""
6+
from selenium import webdriver
7+
from selenium.webdriver.common.by import By
8+
9+
# Firefox webdriver for herokuapp site
10+
fDriver = webdriver.Firefox()
11+
fDriver.get('https://the-internet.herokuapp.com/login')
12+
13+
# fDriver.find_element(By.CLASS_NAME, "").send_keys('tomsmith')
14+
# fDriver.find_element(By.CLASS_NAME, "").send_keys('SuperSecretPassword!')
15+
fDriver.find_element(By.CLASS_NAME, 'radius').click()
16+
17+
# fDriver.quit()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Selecting elements by using CSS selector
3+
"""
4+
from selenium import webdriver
5+
from selenium.webdriver.common.by import By
6+
7+
# Firefox webdriver for herokuapp site
8+
fDriver = webdriver.Firefox()
9+
fDriver.get('https://the-internet.herokuapp.com/login')
10+
11+
fDriver.find_element(By.CSS_SELECTOR, "#username").send_keys('tomsmith')
12+
fDriver.find_element(By.CSS_SELECTOR, "[type=password]").send_keys('SuperSecretPassword!')
13+
fDriver.find_element(By.CSS_SELECTOR, '.radius').click()
14+
15+
# fDriver.quit()

Practice/find-element-by-id.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Selecting elements by using ID
3+
"""
4+
from selenium import webdriver
5+
from selenium.webdriver.common.by import By
6+
7+
# Firefox webdriver for herokuapp site
8+
fDriver = webdriver.Firefox()
9+
fDriver.get('https://the-internet.herokuapp.com/login')
10+
11+
fDriver.find_element(By.ID, "username").send_keys('tomsmith')
12+
fDriver.find_element(By.ID, "password").send_keys('SuperSecretPassword!')
13+
fDriver.find_element(By.CLASS_NAME, 'radius').click()
14+
15+
# fDriver.quit()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Selecting elements by using Partial Link Text (in case of long link names).
3+
Link names must be unique in order to use the PARTIAL_LINK_TEXT option.
4+
"""
5+
from selenium import webdriver
6+
from selenium.webdriver.common.by import By
7+
import time
8+
9+
# Firefox webdriver for herokuapp site
10+
fDriver = webdriver.Firefox()
11+
fDriver.get('https://the-internet.herokuapp.com')
12+
13+
# Goto JavaScript onload event error link
14+
fDriver.find_element(By.PARTIAL_LINK_TEXT, 'JavaScript onload').click()
15+
16+
# time.sleep(2)
17+
# fDriver.quit()

Practice/find-element-by-linktext.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Selecting elements by using Link Text Locator
3+
"""
4+
from selenium import webdriver
5+
from selenium.webdriver.common.by import By
6+
import time
7+
8+
# Firefox webdriver for herokuapp site
9+
fDriver = webdriver.Firefox()
10+
fDriver.get('https://the-internet.herokuapp.com')
11+
12+
# Goto Form Authenticator link
13+
fDriver.find_element(By.LINK_TEXT, 'Form Authentication').click()
14+
15+
# The login page
16+
fDriver.find_element(By.NAME, "username").send_keys('tomsmith')
17+
fDriver.find_element(By.NAME, "password").send_keys('SuperSecretPassword!')
18+
fDriver.find_element(By.CLASS_NAME, 'radius').click()
19+
20+
# time.sleep(2)
21+
# fDriver.quit()

Practice/find-element-by-name.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Selecting elements by using name attribute
3+
"""
4+
from selenium import webdriver
5+
from selenium.webdriver.common.by import By
6+
import time
7+
8+
# Firefox webdriver for herokuapp site
9+
fDriver = webdriver.Firefox()
10+
fDriver.get('https://the-internet.herokuapp.com/login')
11+
12+
fDriver.find_element(By.NAME, "username").send_keys('tomsmith')
13+
fDriver.find_element(By.NAME, "password").send_keys('SuperSecretPassword!')
14+
fDriver.find_element(By.CLASS_NAME, 'radius').click()
15+
16+
time.sleep(2)
17+
# fDriver.quit()

Practice/find-element-by-tagname.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Selecting elements by using Tag Name.
3+
Case when there are more than one html elements with the same name.
4+
"""
5+
from selenium import webdriver
6+
from selenium.webdriver.common.by import By
7+
import time
8+
9+
# Firefox webdriver for herokuapp site
10+
fDriver = webdriver.Firefox()
11+
fDriver.get('https://the-internet.herokuapp.com/')
12+
13+
# Goto tables page
14+
fDriver.find_element(By.LINK_TEXT, 'Sortable Data Tables').click()
15+
16+
# Select all rows from the first table -
17+
# ToDo: Future development
18+
table = fDriver.find_element(By.ID, 'table1')
19+
20+
# time.sleep(2)
21+
# fDriver.quit()

Practice/find-element-by-xpath.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Selecting elements by using XPath
3+
"""
4+
from selenium import webdriver
5+
from selenium.webdriver.common.by import By
6+
7+
# Firefox webdriver for Google site
8+
fDriver = webdriver.Firefox()
9+
fDriver.get('https://the-internet.herokuapp.com/login')
10+
11+
fDriver.find_element(By.XPATH, "//input[@type='text']").send_keys('tomsmith')
12+
fDriver.find_element(By.XPATH, "//input[@type='password']").send_keys('SuperSecretPassword!')
13+
fDriver.find_element(By.XPATH, "//button[@type='submit']").click()
14+
15+
# fDriver.quit()

0 commit comments

Comments
 (0)