예제 #1
0
class Selenium_webdriver:
    def __init__(self, url_address, type="Chrome"):
        """ Return chrome webdriver and open the initial webpage.
        """
        from webdriverwrapper import Chrome
        from selenium import webdriver
        options = webdriver.ChromeOptions()
        options.add_experimental_option("excludeSwitches",
                                        ["enable-automation"])
        options.add_experimental_option('useAutomationExtension', False)
        self.driver = Chrome(options=options)
        # Open a website
        window_before = self.driver.window_handles[0]
        self.driver.get(url_address)

    def get_site_elements(self):
        return None

    def click(self, current_element):
        #self.driver.find_element_by_xpath()
        element = self.driver.find_element_by_name(current_element)
        # the function find_element_by_name should be implemented
        element.click()

    def enter(self, current_element, data):
        element = self.driver.find_element_by_name(current_element)
        enter_field = self.driver.find_element_by_xpath(
            "//input[@name='{}']".format(element))
        enter_field.clear()
        data = generate_data()
        enter_field.send_keys(data)
예제 #2
0
 def __init__(self, url_address, type="Chrome"):
     """ Return chrome webdriver and open the initial webpage.
     """
     from webdriverwrapper import Chrome
     from selenium import webdriver
     options = webdriver.ChromeOptions()
     options.add_experimental_option("excludeSwitches",
                                     ["enable-automation"])
     options.add_experimental_option('useAutomationExtension', False)
     self.driver = Chrome(options=options)
     # Open a website
     window_before = self.driver.window_handles[0]
     self.driver.get(url_address)
예제 #3
0
def setup_chromedriver(mode):
    # configuring chromedriver:
    # my screen res: 1366*768:

    # activate for verbose logging:
    # service_log_path = "chromedriver.log"
    # service_args = ['--verbose']



    chrome_options = Options()

    if mode is 'primary':
        chrome_options.add_argument("--restore-last-session")
        chrome_options.add_argument("user-data-dir=master_profile")
        chrome_options.add_argument("--window-size={},{}".format(1000, 800))
        chrome_options.add_argument("--window-position={},{}".format(1, 1))

    elif mode is 'tertiary':
        chrome_options.add_argument("--window-size={},{}".format(200, 800))
        chrome_options.add_argument("--window-position={},{}".format(1050, 1))

    # get rid off: --ignore-certificate-errors command-line flag warning:
    chrome_options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
    chrome_options.add_argument("--disable-infobars")  # add command line flags

    chrome = Chrome(chrome_options=chrome_options,
                    # service_args=service_args,
                    # service_log_path=service_log_path
                    )

    # log in if not already:
    if 'readcube.com/session/new' in chrome.current_url and mode is 'primary':
        chrome.get('https://app.readcube.com/#/library/collection/~/items')
        # logging in via email / password
        for i in range(5):
            try:
                sleep(3)
                chrome.find_element_by_id('email').send_keys(user)
                chrome.find_element_by_id('password').send_keys(pw)
                chrome.find_element_by_class_name('submit-button').click()
            except Exception as e:
                sleep(1.5)
                # print e
            else:
                break

    # returns driver:
    return chrome
예제 #4
0
 def _get_driver(self):
     return Chrome()
예제 #5
0
# -*- coding: utf-8 -*-

from webdriverwrapper import Chrome


driver = Chrome()
driver.get('http://www.google.com')
driver.click('gbqfsb')
driver.wait_for_element(id_='top-content')
print('Is text "Doodle" in whole page:', driver.contains_text('Doodles'))
print('Is text "Doodle" in footer:', driver.get_elm('footer').contains_text('Doodles'))
driver.quit()
 def _get_driver(self):
     opt = ChromeOptions()
     opt.add_argument('--no-sandbox')
     opt.add_argument('--proxy-auto-detect')
     return Chrome(options=opt)
예제 #7
0
# -*- coding: utf-8 -*-

from webdriverwrapper import Chrome

driver = Chrome()
driver.get('http://www.google.com')
driver.click('gbqfsb')
driver.wait_for_element(id_='top-content')
print('Is text "Doodle" in whole page:', driver.contains_text('Doodles'))
print('Is text "Doodle" in footer:',
      driver.get_elm('footer').contains_text('Doodles'))
driver.quit()
예제 #8
0
def session_driver():
    driver = Chrome()
    yield driver
    driver.quit()
예제 #9
0
def setup_driver(logger, name=None, performance_mode=False):
    '''
    Configures the Chrome driver to run on Jenkins or Windows.
    Also creates and sets the screenshot path
    '''
    date = datetime.datetime.now()
    date = str(date).replace(':', '_').replace('.', '_')
    current = None

    if platform.system() == "Linux":
        my_file = Path("pypyke/screenshots/")
        if my_file.exists():
            os.mkdir(os.path.join("pypyke/screenshots/", name + "_" + date))
            screenshot_path = os.path.join("pypyke/screenshots/",
                                           name + "_" + date)
        else:
            os.mkdir("pypyke/screenshots/")
            os.mkdir(os.path.join("pypyke/screenshots/", name + "_" + date))
            screenshot_path = os.path.join("pypyke/screenshots/",
                                           name + "_" + date)

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--window-size=1920,1080')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        logger.info("detected Linux OS")
    if platform.system() == "Windows":
        current = os.getcwd()
        # if we are not in the python base directory then go to it
        while "pypyke\\" in str(current):
            current = Path(current).parent
        my_file = Path(os.path.join(current, "screenshots"))
        if my_file.exists():
            try:
                os.mkdir(
                    os.path.join(current, "screenshots", name + "_" + date))
            except:
                sleep(1)
                date = datetime.datetime.now()
                date = str(date).replace(':', '_').replace('.', '_')
                os.mkdir(
                    os.path.join(current, "screenshots", name + "_" + date))
            screenshot_path = os.path.join(current, "screenshots",
                                           name + "_" + date)
        else:
            try:
                os.mkdir(os.path.join(current, "screenshots"))
                os.mkdir(
                    os.path.join(current, "screenshots", name + "_" + date))
            except:
                sleep(1)
                date = datetime.datetime.now()
                date = str(date).replace(':', '_').replace('.', '_')
                os.mkdir(os.path.join(current, "screenshots"))
                os.mkdir(
                    os.path.join(current, "screenshots", name + "_" + date))
            screenshot_path = os.path.join(current, "screenshots",
                                           name + "_" + date)

        if performance_mode:
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--window-size=1920,1080')
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--disable-gpu')
            chrome_options.add_experimental_option('useAutomationExtension',
                                                   False)
        else:
            chrome_options = webdriver.ChromeOptions()
            #chrome_options.add_argument('--no-sandbox')
            chrome_options.add_experimental_option('useAutomationExtension',
                                                   False)
            chrome_options.add_argument('--window-size=1920,1080')
        logger.info("detected Windows OS")

    if current:
        driver = Chrome(str(current) + "\\chromedriver.exe",
                        chrome_options=chrome_options)
    else:
        driver = Chrome("chromedriver", chrome_options=chrome_options)

    driver.screenshot_path = screenshot_path
    logger.info("driver object has been created.")
    return driver
예제 #10
0
# -*- coding: utf-8 -*-

from webdriverwrapper import Chrome


driver = Chrome()
driver.get('http://www.google.com')
form_elm = driver.get_elm('gbqf')
form_elm.fill_out_and_submit({
    'q': 'hello world!',
})
driver.wait_for_element(id_='search')
driver.quit()