Created
December 22, 2020 07:00
-
-
Save kurzweil777/b1de59d2f433cfdb42afb1264ca3c34a to your computer and use it in GitHub Desktop.
Selenium Automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.common.exceptions import NoSuchElementException | |
from selenium.webdriver.common.keys import Keys | |
import win10toast | |
from selenium.webdriver.support.ui import WebDriverWait | |
import time | |
path = "C:\Program Files (x86)\chromedriver.exe" | |
driver = webdriver.Chrome(path) | |
toaster = win10toast.ToastNotifier() | |
wait = WebDriverWait(driver, 10) | |
def login(name, passwd): | |
driver.get( | |
"yandex website") # I don't wanna show the actual web-address | |
login = driver.find_element_by_name("login") | |
login.send_keys(name) | |
login.send_keys(Keys.RETURN) | |
time.sleep(5) | |
password = driver.find_element_by_name("passwd") | |
password.send_keys(passwd) | |
password.send_keys(Keys.RETURN) | |
def search_task(): | |
while True: | |
time.sleep(5) | |
try: | |
search = driver.find_element_by_css_selector("div.snippet__title") | |
if search.text != "Name of task": | |
time.sleep(5) | |
driver.refresh() | |
search_task() | |
else: | |
start_btn = driver.find_element_by_css_selector("button.snippet__take-btn") | |
start_btn.click() | |
try: | |
time.sleep(5) | |
back_btn = driver.find_element_by_css_selector("div.base-modal-popup-footer__primary-button") | |
if back_btn: | |
back_btn.click() | |
search_task() | |
except NoSuchElementException: | |
toaster.show_toast("Toloka", "Let's DO THE F*****G JOB!", duration=10) | |
search_task() | |
except NoSuchElementException: | |
time.sleep(60) | |
if __name__ == "__main__": | |
login("your login", "your pass") | |
search_task() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment