from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
import getpass
driver = webdriver.Chrome(
executable_path='/usr/lib/chromium-browser/chromedriver')
driver.maximize_window()
username = input('Enter Your Username: ')
password = getpass.getpass(prompt='Enter Your Password: ')
u = driver.find_element_by_xpath('//*[@id="react-root"]\
/div/div/div[2]/main/div/div/div[2]/form/div/div[1]\
/label/div/div[2]/div/input')
u.send_keys(''+str(username)+'')
p = driver.find_element_by_xpath('//*[@id="react-root"]\
/div/div/div[2]/main/div/div/div[2]/form/div/div[2]\
/label/div/div[2]/div/input')
p.send_keys(''+str(password)+'')
print("loading... \n")
time.sleep(3)
driver.find_element_by_xpath('//*[@id="react-root"]\
/div/div/div[2]/main/div/div/div[2]/form/div/div[3]/div').click()
time.sleep(10)
srch=driver.find_element_by_xpath('//*[@id="react-root"]\
/div/div/div[2]/main/div/div/div/div[2]/div/div[2]\
/div/div/div/div[1]/div/div/div/form/div[1]\
/div/label/div[2]/div/input')
s = input('Enter the Hashtag you want to retweet: ')
srch.send_keys('#'+str(s)+'')
srch.send_keys(Keys.ENTER)
c=int(input('Max no. of Retweets: '))
driver.implicitly_wait(5)
driver.find_element_by_xpath('//*[@id="react-root"]/div/\
div/div[2]/main/div/div/div/div[1]/div/div[1]/div[2]/\
nav/div/div[2]/div/div[2]/a').click()
time.sleep(10)
while(1):
time.sleep(5)
rt = driver.find_elements_by_css_selector(
'.css-18t94o4[data-testid ="retweet"]')
for r in rt:
try:
r.click()
time.sleep(2)
driver.find_element_by_xpath('//*[@id="layers"]/div[2]\
/div/div/div/div[2]/div[3]/div/div/div/div').click()
c -= 1
time.sleep(2)
if(c==0):
break
except (ElementClickInterceptedException, StaleElementReferenceException):
pass
driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
if(c==0):
break
driver.close()