-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_tests_and_workings.py
67 lines (49 loc) · 1.45 KB
/
code_tests_and_workings.py
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
# All links by search
lnks=driver.find_elements_by_tag_name("a")
for lnk in lnks:
# get_attribute() to get all href
print(lnk.get_attribute('href'))
# Click random links in site [ IN PROGRESS ]
while True:
try:
# find element using css selector
links = browser.find_elements_by_css_selector('.post-img-wrap')
print('Im workinggg')
# create a list and chose a random link
l = links[randint(0,len(links)-1)]
# click link
l.click()
# check link
new_page = browser.current_url
# if link is the same, keep looping
if new_page == current_page:
continue
else:
# break loop if you are in a new url
break
except:
continue
# Sending keys
timer
browser.send_Keys(Keys.CONTROL + Keys.TAB)
timer
# Testing code for switching tabsss :D DD
from selenium import webdriver
import time
browser = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
browser.get("https://accounts.google.com/signup")
browser.find_element_by_link_text("Help").click()
#prints parent window title
print("Parent window title: " + driver.title)
#get current window handle
p = browser.current_window_handle
#get first child window
chwd = browser.window_handles
for w in chwd:
#switch focus to child window
if(w!=p):
browser.switch_to.window(w)
break
time.sleep(0.9)
print("Child window title: " + browser.title)
browser.quit()