-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrome.py
More file actions
71 lines (65 loc) · 2.02 KB
/
Copy pathchrome.py
File metadata and controls
71 lines (65 loc) · 2.02 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
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = None
body = None
number_map = {
"first": 1,
"second": 2,
"third": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9,
"ten": 10
}
def open_chrome():
global driver, body
if driver is None:
driver = webdriver.Chrome()
driver.get("https://www.google.com") # ✅ open google instead of chrome.com
time.sleep(3)
body = driver.find_element(By.TAG_NAME, "body")
return "Opening Chrome sir"
else:
return "Chrome already open hai sir"
def search_chrome(query):
global driver, body
if driver is not None:
try:
search_box = driver.find_element(By.NAME, "q") # ✅ google search bar
search_box.clear()
search_box.send_keys(query)
search_box.send_keys(Keys.RETURN)
time.sleep(3)
body = driver.find_element(By.TAG_NAME, "body")
return f"Searching {query} on Chrome"
except Exception as e:
return f"Search bar nahi mila sir: {str(e)}"
else:
return "Chrome abhi open nahi hai sir"
def play_nth_website(n):
global driver, body
if driver is not None:
results = driver.find_elements(By.CSS_SELECTOR, "h3") # ✅ google search results
if len(results) >= n:
results[n - 1].click()
time.sleep(3)
body = driver.find_element(By.TAG_NAME, "body")
return f"Opening website number {n}"
else:
return f"Sir, sirf {len(results)} results available hain"
else:
return "Chrome abhi open nahi hai sir"
def close_chrome():
global driver, body
if driver is not None:
driver.quit()
driver = None
body = None
return "Closing Chrome sir"
else:
return "Chrome already closed"