-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateSearch.py
More file actions
77 lines (71 loc) · 2.66 KB
/
validateSearch.py
File metadata and controls
77 lines (71 loc) · 2.66 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
# Selenium Tutorial #2
# Perform a search and validate the results
# Import required modules
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
import time
# Initialize the webdriver
driver = webdriver.Edge()
# Go to the website
driver.get("https://www.newgrounds.com")
# Wait for the search bar
try:
topsearch = WebDriverWait(driver, 10).until (
EC.presence_of_element_located((By.ID, "topsearch_text"))
)
# Ensure the search bar is clear
topsearch.clear()
# Perfom a search
topsearch.send_keys("Linkin Park")
time.sleep(1)
topsearch.send_keys(Keys.RETURN)
except TimeoutException:
print("Timeout")
# Wait for the page elements
try:
results = WebDriverWait(driver, 10).until (
EC.presence_of_element_located((By.XPATH, "//div[starts-with(@id, 'search_results_container_')]"))
)
# Validate Creations titles match search
print()
print("/" * 8, "Creations", "/" * 8)
print()
itemlist1 = driver.find_elements(By.XPATH, "//div[starts-with(@id, 'search_results_container_')]/ul[1]")
for item in itemlist1:
creations = item.find_elements(By.CLASS_NAME, "item-details")
for creation in creations:
titles = creation.find_elements(By.CLASS_NAME, "detail-title")
for title in titles:
print(title.text)
# Validate Linkin and/or Park is in the text-content in the Community
print()
print("/" * 8, "Community", "/" * 8)
print()
itemlist2 = driver.find_elements(By.XPATH, "//div[starts-with(@id, 'search_results_container_')]/ul[2]")
for item in itemlist2:
posts = item.find_elements(By.CLASS_NAME, "searchitem-community-post")
for post in posts:
highlights = post.find_elements(By.CLASS_NAME, "search-highlight")
for highlight in highlights:
print(highlight.text)
# Validate the number of Users
print()
print("/" * 8, "Users", "/" * 8)
print()
itemlist3 = driver.find_elements(By.XPATH, "//div[starts-with(@id, 'search_results_container_')]/ul[3]")
for item in itemlist3:
users = item.find_elements(By.CLASS_NAME, "item-user")
if len(users) == 10:
print("The number of users are: ", len(users))
else:
print("Error: missing users")
print()
except TimeoutException:
print("Timeout")
# Exit the borwser
driver.quit()