-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNear_Relative_Locator_Selenium_4.py
More file actions
127 lines (102 loc) · 4.27 KB
/
Copy pathNear_Relative_Locator_Selenium_4.py
File metadata and controls
127 lines (102 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import sys
import json
import time
import pytest
import urllib3
import warnings
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.relative_locator import with_tag_name
browser_capabilities = {
"user" : "user.name",
"accessKey" : "Access-Key",
"build" : "[Python] - Login Page",
"name" : "[Python] - Login Page",
"platformName" : "OS X Mavericks",
"browserName" : "Chrome",
"browserVersion" : "67.0"
}
user_name = "user-name"
app_key = "access-key"
def start_todo_app():
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
remote_url = "https://" + user_name + ":" + app_key + "@bm.com/wd/hub"
web_driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = browser_capabilities)
web_driver.get('https://accounts.hey.com/login')
web_driver.maximize_window()
elem_label = web_driver.find_element(By.CSS_SELECTOR,".orsignup")
elementBox = web_driver.find_elements(with_tag_name("input").below(elem_label))
for items in elementBox:
# print(items.get_attribute('name'))
elem_name = items.get_attribute('name')
if (elem_name == "email"):
# print("Inside Email Address")
web_driver.find_element(By.NAME, elem_name).send_keys("Email@gmail.com")
if (elem_name == "password"):
# print("Inside Password")
web_driver.find_element(By.NAME, elem_name).send_keys("Himanshu1!")
web_driver.find_element(By.XPATH, "//span[@class='input-group-text password-group-text']").click()
break
sleep(3)
web_driver.find_element(By.CSS_SELECTOR, ".btn").click()
sleep(3)
window_title = web_driver.title
# print(window_title)
expected_title = "Welcome"
if expected_title in window_title:
print("Login successful")
else:
print("Login not successful")
print("Relative Locators in Selenium 4 on LambdaTest Login Page complete")
web_driver.quit()
# Relative Locators
import sys
import json
import time
import pytest
import urllib3
import warnings
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.relative_locator import with_tag_name
browser_capabilities = {
"user" : "user.name",
"accessKey" : "Access-Key",
"build" : "[Python] - Relative Locators in Selenium 4 on Login Page",
"name" : "[Python] - Relative Locators in Selenium 4 on Login Page",
"platformName" : "OS X Mavericks",
"browserName" : "Chrome",
"browserVersion" : "67.0"
}
# Example 2 Above
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
password_field = driver.find_element(By.ID, "password")
email_address_field = driver.find_element(locate_with(By.TAG_NAME, "input").above(password_field))
# Example 3 Below
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
email_address_field = driver.find_element(By.ID, "email")
password_field = driver.find_element(locate_with(By.TAG_NAME, "input").below(email_address_field))
# Example 4 To the Left Of
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
submit_button = driver.find_element(By.ID, "submit")
cancel_button = driver.find_element(locate_with(By.TAG_NAME, "button").
to_left_of(submit_button))
# To the Right Of
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
cancel_button = driver.find_element(By.ID, "cancel")
submit_button = driver.find_element(locate_with(By.TAG_NAME, "button").
to_right_of(cancel_button))
# Near
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
email_address_label = driver.find_element(By.ID, "lbl-email")
email_address_field = driver.find_element(locate_with(By.TAG_NAME, "input").
near(email_address_label))