Skip to content

Commit 0ae1a93

Browse files
authored
Add files via upload
1 parent 69c4bf3 commit 0ae1a93

File tree

7 files changed

+309
-0
lines changed

7 files changed

+309
-0
lines changed

Day_14/Slider_drag_drop_5.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# in the slider drag and drop we have two ends
2+
# one is called minimum and the other is called maximum
3+
# first we have to find the position/location of those elements (ends)
4+
# if the elements are located on X-axis we have to change their values for changing the position of sliders
5+
# same process will be repeated if the elements are located on y-axis
6+
# to the minimum side on axis we will add values and for the maximum we will substract values to change their poisition/location
7+
8+
import time
9+
from selenium import webdriver
10+
from selenium.webdriver import ActionChains
11+
from selenium.webdriver.chrome.service import Service
12+
from selenium.webdriver.common.by import By
13+
14+
options = webdriver.ChromeOptions()
15+
options.add_experimental_option("detach", True)
16+
17+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
18+
driver = webdriver.Chrome(options=options, service=ser_obj)
19+
20+
driver.implicitly_wait(3)
21+
driver.get("https://www.globalsqa.com/demoSite/practice/slider/range.html")
22+
23+
min_slider = driver.find_element(By.XPATH, "//span[1]")
24+
max_slider = driver.find_element(By.XPATH, "//span[2]")
25+
26+
print("location before moving the sliders")
27+
print(min_slider.location) # {'x': 152, 'y': 47}
28+
print(max_slider.location) # {'x': 611, 'y': 47}
29+
30+
# now as it is horizontal slider and we are moving on x_axis so y_axis is will not change
31+
# we will only increase or decrease values for the x-axis and y-axis values will be zero
32+
33+
act = ActionChains(driver)
34+
35+
act.drag_and_drop_by_offset(min_slider, 70 , 0).perform() # pass the element, X-offset and y-offset value
36+
act.drag_and_drop_by_offset(max_slider, -60 , 0).perform()
37+
38+
39+
print("location after moving the sliders")
40+
print(min_slider.location) # {'x': 224, 'y': 47}
41+
print(max_slider.location) # {'x': 552, 'y': 47}
42+
43+
# as we can see that i have added 70 to the x-offset and it should be 222 but it is 224
44+
# the differnce is always there because the resolution of the screens are different that is why
45+
46+
time.sleep(3)
47+
driver.close()

Day_14/double_click_3.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# double click operation
2+
3+
import time
4+
from selenium import webdriver
5+
from selenium.webdriver import ActionChains
6+
from selenium.webdriver.chrome.service import Service
7+
from selenium.webdriver.common.by import By
8+
9+
options = webdriver.ChromeOptions()
10+
options.add_experimental_option("detach", True)
11+
12+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
13+
driver = webdriver.Chrome(options=options, service=ser_obj)
14+
15+
driver.implicitly_wait(3)
16+
17+
driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_ondblclick")
18+
19+
# text = "Hello World"
20+
21+
# as the element is in Iframe so we have to switch to the frame
22+
driver.switch_to.frame("iframeResult")
23+
24+
button = driver.find_element(By.XPATH, "//button[normalize-space()='Double-click me']")
25+
26+
act = ActionChains(driver)
27+
28+
act.double_click(button).perform()
29+
30+
# p = driver.find_element(By.XPATH, "//p[@id='demo']")
31+
32+
# if p.text == text:
33+
# print("test case passed")
34+
# else:
35+
# print("test case failed")
36+
37+
38+
time.sleep(3)
39+
driver.close()

Day_14/drag_and_drop_4.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# The two main thing you need to know while performing the drag and drop
2+
# source element and target element
3+
4+
import time
5+
from selenium import webdriver
6+
from selenium.webdriver import ActionChains
7+
from selenium.webdriver.chrome.service import Service
8+
from selenium.webdriver.common.by import By
9+
10+
options = webdriver.ChromeOptions()
11+
options.add_experimental_option("detach", True)
12+
13+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
14+
driver = webdriver.Chrome(options=options, service=ser_obj)
15+
16+
driver.implicitly_wait(3)
17+
18+
driver.get("http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html")
19+
20+
# source and target element for the rome element
21+
src_ele = driver.find_element(By.XPATH, "//div[@id='box6']")
22+
tar_ele = driver.find_element(By.XPATH, "//div[@id='box106']")
23+
24+
act = ActionChains(driver)
25+
26+
# Pass the src and trg element to the method
27+
act.drag_and_drop(src_ele, tar_ele).perform()
28+
29+
# to perform it for multiple elements repeat the same process
30+
31+
time.sleep(3)
32+
driver.close()

Day_14/mouse_operation_1.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Mouse operation
2+
# when we want to double click or do something in by mouse in automation it is called mouse operartion
3+
# for that we use a class called 'ActionChains'
4+
# 1: Mouse hover
5+
# 2: Right click
6+
# 3: Double click
7+
# 4: Drag & Drop
8+
9+
import time
10+
from selenium import webdriver
11+
from selenium.webdriver import ActionChains
12+
from selenium.webdriver.chrome.service import Service
13+
from selenium.webdriver.common.by import By
14+
15+
options = webdriver.ChromeOptions()
16+
options.add_experimental_option("detach", True)
17+
18+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
19+
driver = webdriver.Chrome(options=options, service=ser_obj)
20+
21+
driver.implicitly_wait(3)
22+
driver.get("https://practice.expandtesting.com/hovers")
23+
hover1 = driver.find_element(By.XPATH, "//div[@class='container']//div[1]//img[1]")
24+
hover2 = driver.find_element(By.XPATH, "/html[1]/body[1]/main[1]/div[1]/div[1]/div[1]/div[1]/a[1]")
25+
26+
# To perform Mouse Operations we have to import a class 'ActionChains' & make its objects
27+
# ActionChains require 'driver' instance to be passed to it
28+
29+
act_obj = ActionChains(driver)
30+
31+
# move_to_element is used for mouse hover operation
32+
# upto click it is only action making. perform is used to execute that action
33+
act_obj.move_to_element(hover1).move_to_element(hover2).click().perform()
34+
35+
print("Test case Passed !")
36+
37+
time.sleep(3)
38+
driver.close()

Day_14/right_click_2.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Sometime you are required to right click on a button or text to perform an action
2+
# for that purpose we use right click mouse action to proceed further
3+
4+
import time
5+
from selenium import webdriver
6+
from selenium.webdriver import ActionChains
7+
from selenium.webdriver.chrome.service import Service
8+
from selenium.webdriver.common.by import By
9+
10+
options = webdriver.ChromeOptions()
11+
options.add_experimental_option("detach", True)
12+
13+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
14+
driver = webdriver.Chrome(options=options, service=ser_obj)
15+
16+
driver.implicitly_wait(3)
17+
driver.get("https://swisnl.github.io/jQuery-contextMenu/demo.html")
18+
19+
button = driver.find_element(By.XPATH, "//span[@class='context-menu-one btn btn-neutral']")
20+
21+
act = ActionChains(driver) # create Action
22+
23+
act.context_click(button).perform() # perform Right click action
24+
25+
26+
# Note : uncomment this section if you want to see the extra steps in browser
27+
# time.sleep(2)
28+
# copy = driver.find_element(By.XPATH, "//span[normalize-space()='Copy']")
29+
# copy.click()
30+
31+
# driver.switch_to.alert.accept()
32+
33+
time.sleep(3)
34+
35+
driver.close()

Day_14/scrolling_6.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# scrolling is also mouse operation but we can't perform it using actionchains
2+
# it is because when content of the web page can't be showed on one page then scroll bar is added by the browser
3+
# so scroll bar is not from the application it is from the browser hence can't be handled by actionchains
4+
# as scoll bar is designed using javascript so we have to write some script to handle it
5+
# there are four ways in which we can perform scrolling
6+
# Note : uncomment the option you want to test
7+
8+
import time
9+
from selenium import webdriver
10+
from selenium.webdriver import ActionChains
11+
from selenium.webdriver.chrome.service import Service
12+
from selenium.webdriver.common.by import By
13+
14+
options = webdriver.ChromeOptions()
15+
options.add_experimental_option("detach", True)
16+
17+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
18+
driver = webdriver.Chrome(options=options, service=ser_obj)
19+
20+
driver.implicitly_wait(3)
21+
driver.get("https://www.countries-ofthe-world.com/flags-of-the-world.html")
22+
23+
# 1 : scoll down page by pixels
24+
25+
# driver.execute_script("window.scrollBy(0,3000)") # inside the execute we passed javascript statement and passed a window methode
26+
# # we use execute_script for executing javascript statements
27+
28+
# value = driver.execute_script("return window.pageYOffset;") # semicolon will also be added since it is JS
29+
# print("number of pixel scrollbar moved: ", value) # 2999
30+
31+
# 2 : scoll down page till the element is visible/found
32+
# for that we have to first capture that element
33+
34+
# flag = driver.find_element(By.XPATH, "//img[@alt='Flag of Pakistan']")
35+
# driver.execute_script("arguments[0].scrollIntoView()",flag) # passed two arguments
36+
37+
38+
# now if you want to know how much the scroll bar is moved use this statement
39+
# value = driver.execute_script("return window.pageYOffset;")
40+
# print("number of pixel scrollbar moved: ", value)
41+
42+
# 3 : scroll down till the end page
43+
driver.execute_script("window.scrollBy(0, document.body.scrollHeight)", "")
44+
45+
# now if you want to know how much the scroll bar is moved use this statement
46+
value = driver.execute_script("return window.pageYOffset;")
47+
print("number of pixel scrollbar moved: ", value) # 9560.7548828125
48+
49+
time.sleep(4)
50+
51+
# 4 : scroll up the page to the start
52+
driver.execute_script("window.scrollBy(0, -document.body.scrollHeight)", "") # here we have added the substract sign
53+
54+
time.sleep(3)
55+
driver.close()

Day_15/keyboardaction-1.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# through action chains we can also perform keybaordactions
2+
3+
import time
4+
from selenium import webdriver
5+
from selenium.webdriver.common.keys import Keys
6+
from selenium.webdriver import ActionChains
7+
from selenium.webdriver.chrome.service import Service
8+
from selenium.webdriver.common.by import By
9+
10+
options = webdriver.ChromeOptions()
11+
options.add_experimental_option("detach", True)
12+
13+
ser_obj = Service("C:\Drivers\chromedriver\chromedriver.exe")
14+
driver = webdriver.Chrome(options=options, service=ser_obj)
15+
16+
driver.implicitly_wait(3)
17+
driver.get("https://gotranscript.com/text-compare")
18+
driver.maximize_window()
19+
20+
# we will send text from one input box to another for that we will perform following keyboard actions
21+
# Ctrl+a ----> ctrl+c ----> tab ----> ctrl+v
22+
23+
# first capture the input boxes
24+
input1 = driver.find_element(By.XPATH, "//textarea[@name='text1']")
25+
input2 = driver.find_element(By.XPATH, "//textarea[@name='text2']")
26+
input1.send_keys("Free Palestine")
27+
28+
29+
act = ActionChains(driver)
30+
31+
time.sleep(3)
32+
act.key_down(Keys.CONTROL) # now for holding the ctrl
33+
act.send_keys("a") # ctrl + a for selecting all text
34+
act.key_up(Keys.CONTROL) # for releasing the ctrl key
35+
act.perform()
36+
37+
# you can also write the above statement like this
38+
# act.key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).perform()
39+
40+
act.key_down(Keys.CONTROL)
41+
act.send_keys("c")
42+
act.key_up(Keys.CONTROL)
43+
act.perform()
44+
45+
# now switch to the other box
46+
act.send_keys(Keys.TAB).perform()
47+
48+
49+
# now paste it to the other box
50+
act.key_down(Keys.CONTROL).send_keys("v").key_up(Keys.CONTROL).perform()
51+
52+
# compare1 = "100%"
53+
# driver.find_element(By.XPATH, "//button[@id='recaptcha']").click()
54+
# compare2 = driver.find_element(By.XPATH, "//div[@class='s-text-compare']//div[@class='col']//div[3]/child::b").text
55+
56+
57+
# if compare1 == compare2:
58+
# print("test case passed !")
59+
# else:
60+
# print("test case failed !")
61+
62+
time.sleep(3)
63+
driver.close()

0 commit comments

Comments
 (0)