-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeleniumTask.py
More file actions
88 lines (57 loc) · 2.62 KB
/
SeleniumTask.py
File metadata and controls
88 lines (57 loc) · 2.62 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
import re
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
def driverInitialize(driver_path):
"Please replace the driver_path below according to your own driver location"
# driver can by changed according to browser driver
driver = webdriver.Chrome(driver_path)
return driver
def resultsNumber(driver,search_string,search_engine):
"Function will search claroty at google and print to console results number"
# open google
driver.get(search_engine)
# locate the search field
search = driver.find_element_by_name('q')
# type "Claroty" into search field
search.send_keys(search_string)
# hit return after you enter search text
search.send_keys(Keys.RETURN)
# locate the resultStats element
result_str = driver.find_element_by_id('resultStats')
# using regex for get only integer result
res_dig = int(''.join(elem for elem in re.findall(r'\d*', re.sub(r'\(.*?\)', '', result_str.text)) if elem.isdigit()))
# print the text of resultStats
print("Results number by google search for Claroty is about: " , res_dig)
def firstLink(driver , url_first_link):
"Function will check if claroty.com is the first results link"
# finds webresults
links_list = driver.find_elements_by_xpath('//div[@class="r"]/a/h3')
# clicks the first link
links_list[0].click()
# check if link is claroty.com
if driver.current_url == url_first_link:
print(driver.current_url , 'Is the first link of google search results')
else:
print(url_first_link, "Is not the first link of google search results")
def clarotyJobs(driver, careers_url):
"Function will check how many visible jobs exist at careers page"
driver.get(careers_url)
# find class name of jobs in our web
elements = driver.find_elements_by_class_name('w-dyn-item')
# sub function that calculating the number of the visible jobs only
numberOfVisibleItems = 0
for item in elements:
children = item.find_elements_by_xpath('div')
for child in children:
classString = child.get_attribute('class')
if "w-condition-invisible" not in classString:
numberOfVisibleItems = numberOfVisibleItems + 1
break
print("number of carriers available:", numberOfVisibleItems)
def exit(driver):
"Function will give us few sec to see the browser and then will close him"
# sleep for 5 seconds so you can see the results
time.sleep(5)
# Close the browser
driver.quit()