Exemplo n.º 1
0
    def browser(self):
        config_browser = self.config_browser()
        config_wait_time = self.config_wait_time()
        config_headless = self.headless_browser()

        if config_browser == 'chrome':
            if config_headless == 'yes':
                driver_options = chrome_options()
                driver_options.headless = True
                driver = Chrome(options=driver_options)
            else:
                driver = Chrome()
        elif config_browser == 'firefox':
            if config_headless == 'yes':
                driver_options = ff_options()
                driver_options.headless = True
                driver = Firefox(options=driver_options)
            else:
                driver = Firefox()
        elif config_browser == 'opera':
            if config_headless == 'yes':
                driver_options = opera_options()
                driver_options.headless = True
                driver = Opera(options=driver_options)
            else:
                driver = Opera()
        else:
            raise Exception(f'"{config_browser}" is not a supported browser')

        driver.implicitly_wait(config_wait_time)

        return driver
Exemplo n.º 2
0
def create_instance(*, headless=False, auto_quit=True, user_data_dir=None, executable_path=None) -> Opera:
    """Creates Opera webdriver instance using the provided arguments."""

    _log.debug("creating webdriver: Opera(headless=%s, auto_quit=%s, user_data_dir='%s', executable_path='%s')",
               headless, auto_quit, user_data_dir, executable_path)

    options = get_options(headless=headless, user_data_dir=user_data_dir)
    driver = Opera(options=options, executable_path=executable_path)
    _log.debug("created webdriver: Opera")

    if auto_quit:
        atexit.register(driver.quit)

    return driver
Exemplo n.º 3
0
from selenium.webdriver import Opera

browser = Opera(executable_path="/Users/macbook/webdriver/operadriver")
browser.get('https://mail.ru')
browser.find_element_by_name("login").send_keys('*****@*****.**')
browser.find_element_by_id("mailbox:submit").click()
browser.implicitly_wait(5)
browser.find_element_by_name("password").send_keys('O+ryrpoAOY24')
browser.find_element_by_id("mailbox:submit").click()
print(browser.title)
def start_browsing(site):
    driver = Opera()
    driver.get(site)
    # be sure we are in stack overflow
    assert 'Stack Overflow' in driver.title, 'It seems like its not Stack Overflow'
    return driver
Exemplo n.º 5
0
    def test_cartCost(self):
        opts = Options()
        opts.headless = True
        assert opts.headless  # без графического интерфейса.
        browser = Opera(options=opts)

        browser.get('https://luch.by/kollektsii/volat-2-0/728377624/')
        item1Price = int(browser.find_element_by_class_name('styled-price').text[:-4])
        browser.find_element_by_class_name('button_add').click()

        browser.get('https://luch.by/kollektsii/classic/76730567/')
        item2Price = int(browser.find_element_by_class_name('styled-price').text[:-4])
        browser.find_element_by_class_name('button_add').click()

        browser.get('https://luch.by/cart/')
        total = int(browser.find_element_by_class_name('styled-price').text[:-4])
        self.assertEqual(total, item1Price+item2Price)
Exemplo n.º 6
0
class BrowserBot:
    def __init__(self):
        self.driver = Opera(executable_path='./operadriver')
        self.driver.get("https://nofluffjobs.com/pl")
        self.driver.fullscreen_window()
        self.jobs_descriptions = []
        self.jobs_links = []

    def click_confirm_button(self):
        try:
            buttons = WebDriverWait(self.driver, 10).until(
                EC.presence_of_all_elements_located((By.CLASS_NAME, "btn")))
            for button in buttons:
                if button.text == "Zatwierdź":
                    button.click()
                    break
        except NoSuchElementException:
            print("Error in click_confirm_button()")
            self.driver.quit()

    def print_job_offers(self):
        print(f"FOUND {len(self.jobs_links)} JOBS\n-------------")
        for i in range(len(self.jobs_links)):
            print(
                f"{i + 1}: {self.jobs_descriptions[i]} \t LINK:{self.jobs_links[i]}"
            )

    def collect_jobs_descriptions(self):
        try:
            time.sleep(1)
            headers = WebDriverWait(self.driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CLASS_NAME, 'posting-list-item')))

            for header in headers:
                self.jobs_descriptions.append(list(header.text.split("\n"))[0])

        except NoSuchElementException:
            print("Error in collect_jobs_description()")
            self.driver.quit()

    def collect_jobs_links(self):
        try:
            links = self.driver.find_elements_by_xpath('.//a')
            for link in links:
                if re.search("^.*/job/.*$", str(link.get_attribute('href'))):
                    self.jobs_links.append(link.get_attribute('href'))
        except NoSuchElementException:
            print("Error in collect_jobs_links()")
            self.driver.quit()

    def page_scroll(self, scroll_list):
        pages = WebDriverWait(self.driver, 10).until(
            EC.presence_of_all_elements_located((By.CLASS_NAME, "page-item")))
        checkpoint = False
        for page in pages:
            if checkpoint and (page.text == str(scroll_list[0] + 1)):
                scroll_list[1] = True
            if page.text == str(scroll_list[0]):
                try:
                    self.driver.implicitly_wait(1)
                    page.click()
                except NoSuchElementException:
                    print("Error in page_scroll()")
                    self.driver.quit()
                checkpoint = True
                continue

    def collect_job_offers(self):
        self.driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight - 1500);")
        pages_available = WebDriverWait(self.driver, 10).until(
            EC.presence_of_all_elements_located((By.CLASS_NAME, "page-item")))
        check = False
        for pa in pages_available:
            if pa.text == str(2):
                check = True
        scroll_list = [2, False]
        self.collect_jobs_links()
        self.collect_jobs_descriptions()
        if check:
            while True:
                scroll_list[1] = False
                self.driver.execute_script(
                    "window.scrollTo(0, document.body.scrollHeight - 1500);")
                self.page_scroll(scroll_list)
                self.collect_jobs_descriptions()
                self.collect_jobs_links()
                scroll_list[0] = scroll_list[0] + 1
                if not scroll_list[1]:
                    break

    def choose_location_filters(self, user_input):
        filters = self.driver.find_elements_by_class_name("d-inline-block")
        for site_filter in filters:
            if site_filter.text == "Lokalizacje":
                site_filter.click()
        try:
            elements = WebDriverWait(self.driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CLASS_NAME, "filters-btn")))
            for element in elements:
                if element.text in user_input:
                    element.click()
        except NoSuchElementException:
            print("Error in find_location_filter()")
            self.driver.quit()

    def choose_level_filters(self, user_input):
        filters = self.driver.find_elements_by_class_name("d-inline-block")
        for site_filter in filters:
            if site_filter.text == "Więcej":
                site_filter.click()
        try:
            labels = WebDriverWait(self.driver, 10).until(
                EC.presence_of_all_elements_located((By.TAG_NAME, "label")))
            for label in labels:
                try:
                    if label.text in user_input:
                        label.click()
                except NoSuchElementException:
                    print("Error in choose_level_filters()")
                    self.driver.quit()
        except NoSuchElementException:
            print("Error in choose_level_filters()")
            self.driver.quit()

    def choose_category(self, user_input):
        filters = self.driver.find_elements_by_class_name("d-inline-block")
        for site_filter in filters:
            if site_filter.text == "Kategoria":
                site_filter.click()
        try:
            elements = WebDriverWait(self.driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CLASS_NAME, "filters-btn")))
            for proper_element in elements:
                if proper_element.text in user_input:
                    proper_element.click()
        except NoSuchElementException:
            print("Error in find_location_filter()")
            self.driver.quit()

    def close_browser(self):
        self.driver.quit()
Exemplo n.º 7
0
 def __init__(self):
     self.driver = Opera(executable_path='./operadriver')
     self.driver.get("https://nofluffjobs.com/pl")
     self.driver.fullscreen_window()
     self.jobs_descriptions = []
     self.jobs_links = []