-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinod.py
54 lines (38 loc) · 1.58 KB
/
Binod.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
from selenium import webdriver
import subprocess,time,sys
from selenium.webdriver.common.keys import Keys
# Number of times you want to run
n=int(input("Enter number of times you want to run: \n"))
# executing the windows batch file to open chrome
p=subprocess.Popen(r'C:\Users\Yash Patel\Desktop\python\Binod\chrome.bat',shell=True)
# Adding repo's path so that chrome web driver can be called
# sys.path.append(r'C:\Users\Yash Patel\Desktop\Python\Binod')
# Attaching selenium to opened browser
options= webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
options.add_argument("--start-maximized")
driver=webdriver.Chrome(options=options)
# opening youtube
time.sleep(2)
driver.get("https://youtube.com")
if n>0:
# Clicking the first video from recommendation
vid1=driver.find_element_by_xpath('//*[@id="video-title"]')
vid1.click()
i=0
while i<n:
i+=1
# wait for browser to scroll down
time.sleep(2)
driver.execute_script("window.scrollTo(0, 720);")
time.sleep(2)
# find comment box and click on it
commentbox=driver.find_element_by_xpath('//*[@id="placeholder-area"]')
commentbox.click()
# Enter text
comment_input=driver.find_element_by_xpath('//*[@id="contenteditable-root"]')
comment_input.send_keys('BINOD')
# post the comment and go to next video
webdriver.ActionChains(driver).key_down(Keys.CONTROL).key_down(Keys.ENTER).key_up(Keys.CONTROL).key_up(Keys.ENTER).perform()
time.sleep(2)
webdriver.ActionChains(driver).key_down(Keys.SHIFT).send_keys('n').key_up(Keys.SHIFT).perform()