class AddAToDoText(unittest.TestCase):
    def setUp(self):
        options = EdgeOptions()
        options.use_chromium = True
        options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe"
        dir = os.path.dirname(os.path.realpath(__file__))
        edge_driver_path = dir + "\\edgedriver_win64\\msedgedriver.exe"
        self.service = Service(edge_driver_path)
        self.service.start()
        self.driver = Edge(options=options, service=self.service)
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
        self.driver.get("http://*****:*****@class='toggle']/following-sibling::label").get_attribute(
                "innerText")
        self.assertEqual("The test is adding this todo", addedToDoText)

    def tearDown(self):
        self.driver.quit()
        self.service.stop()
Пример #2
0
 def __init__(self, headless=True, options=[], path='myengine\MicrosoftWebDriver'):
     # browser_options = EdgeOptions()
     # for _ in options:
     #     browser_options.add_argument(_)
     # Edge.__init__(self, options=browser_options, executable_path=path)
     Edge.__init__(self, executable_path=path)
     Browser.__init__(self)
Пример #3
0
    def __init__(self):
        self.logger = logging.getLogger(LOGGER_INSTANCE)

        if TARGET_BROWSER == 'chrome':
            self.browser = Chrome()
        elif TARGET_BROWSER == 'firefox':
            self.browser = Firefox()
        elif TARGET_BROWSER == 'edge':
            self.browser = Edge()
Пример #4
0
 def setUp(self):
     logging.info("(Edge)## -- Entering 'setUp()' method -- ##")
     try:
         self.driver = Edge(executable_path=r'E:\Pawan\Selenium\WebAppTests_Empirix\drivers\msedgedriver.exe')
         self.driver.implicitly_wait(30)
         self.driver.maximize_window()
         self.driver.get("https://services.empirix.com/")
     except Exception as e:
         logging.exception("(Edge)Issue in func setUp() - " + str(e))
         logging.exception(traceback.format_exc())
Пример #5
0
def edge_driver(request: "SubRequest") -> Union[Remote, Edge]:
    """Fixture for receiving selenium controlled Edge instance"""
    if request.cls.test_type == "edge-local":
        driver = Edge()
    else:
        executor = RemoteConnection(SAUCE_HUB_URL, resolve_ip=False)
        driver = Remote(desired_capabilities=SAUCE_EDGE,
                        command_executor=executor)
    set_selenium_driver_timeouts(driver)
    request.cls.driver = driver
    yield driver
    driver.close()
 def setUp(self):
     options = EdgeOptions()
     options.use_chromium = True
     options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe"
     dir = os.path.dirname(os.path.realpath(__file__))
     edge_driver_path = dir + "\\edgedriver_win64\\msedgedriver.exe"
     self.service = Service(edge_driver_path)
     self.service.start()
     self.driver = Edge(options=options, service=self.service)
     self.driver.implicitly_wait(30)
     self.driver.maximize_window()
     self.driver.get("http://localhost:4200")
Пример #7
0
def drivergen():
    # --------------------------------------handle the driver-----------------------------------------------#
    print(
        "\n\nDownload the driver and put it in the same folder with this file")
    print("Detecting drivers in current folder: " + os.getcwd() + "...")
    if not ChromeDriverExist() and MsEdgeDriverExist():
        print("Found Edge driver")
        br_option = input("Are you want to continue?\n>")
        if br_option.lower() == "y" or br_option.lower() == "yes":
            return Edge(executable_path=".\\msedgedriver.exe")
        else:
            PATH = inputFilepath("Full path to driver = ",
                                 blank=False,
                                 mustExist=True)
            return Edge(executable_path=PATH)
    elif not MsEdgeDriverExist() and ChromeDriverExist():
        print("Found Chrome driver")
        br_option = input("Are you want to continue?\n>")
        if br_option.lower() == "y" or br_option.lower() == "yes":
            return Chrome(executable_path=".\\chromedriver.exe")
        else:
            print("Please enter full path for Chrome driver")
            PATH = inputFilepath("Full path to driver = ",
                                 blank=False,
                                 mustExist=True)
            return Chrome(executable_path=PATH)
    elif MsEdgeDriverExist() and ChromeDriverExist():
        print("Found both edge and chrome driver, choose which?\n")
        print("E  -------  Edge")
        print("C  -------  Chrome")
        br_option = input("\nI choose ")
        if br_option.lower() == "c" or br_option.lower() == "chrome":
            print("Set to chrome")
            return Chrome(executable_path=".\\chromedriver.exe")
        else:
            print("Set to edge")
            return Edge(executable_path=".\\msedgedriver.exe")
    else:
        print("Unable to locate the driver...")
        print("Choose the broser type?\n")
        print("E  -------  Edge")
        print("C  -------  Chrome")
        br_option = input("\nI choose ")
        if br_option.lower() == "c" or br_option.lower() == "chrome":
            PATH = inputFilepath("Full path to driver = ",
                                 blank=False,
                                 mustExist=True)
            return Chrome(executable_path=PATH)
        else:
            PATH = input("FULL PATH to edge driver = ")
            return Edge(executable_path=PATH)
Пример #8
0
 def InitializeSession(self):
     try:
         if self.browser_type == 'CHROME':
             return Chrome(self.path, options=self.options)
         elif self.browser_type == 'FIREFOX':
             return Firefox(self.path, options=self.options)
         elif self.browser_type == 'EDGE':
             return Edge(self.path, options=self.options)
     except:
         sys.exit(
             'Could not find driver for what you specified or there occurred unidentified error.'
         )
Пример #9
0
class SawFirst:
    def __init__(self, url):
        self.driver = Edge(executable_path=PATH)
        self.driver.get(url)

    def _get_links(self, s):
        links = self.driver.find_elements_by_xpath('//a')
        sorted_links = [link for link in links if link.text.find(s, 0) != -1]
        return sorted_links

    def go_to_page(self, s):
        # for link in self._get_links(s):
        #     link.click()
        link = self._get_links(s)[0]
        link.click()
        time.sleep(2)
        try:
            gallery = self.driver.find_element_by_id('gallery-1')
            image_links = gallery.find_elements_by_tag_name('a')
        except Exception:
            pass
        else:
            time.sleep(1)
            image_links[0].click()
            ui.WebDriverWait(self.driver, 3000).until(
                expected_conditions.element_to_be_clickable(
                    (By.CLASS_NAME, 'featured-image2')))
            self.driver.find_element_by_class_name('featured-image2')
Пример #10
0
def main():
    start_time = time.time()
    print("Reading profile path")
    file = open("PROFILE_PATH", "r")
    parameter1 = file.readline()
    parameter2 = file.readline()
    file.close()
    edge_options = EdgeOptions()
    edge_options.use_chromium = True
    #edge_options.add_argument("-inprivate")
    edge_options.add_experimental_option(
        "detach", True)  # Keep browser open after the program finishes running
    argument1 = "user-data-dir=" + parameter1
    edge_options.add_argument(argument1)
    argument2 = "profile-directory=" + parameter2
    edge_options.add_argument(argument2)
    path = Service("msedgedriver.exe")
    browser = Edge(service=path, options=edge_options)
    browser.get("https://account.microsoft.com/rewards/")

    # Wait for manual login
    print(" _                 _      ___     __         __  __  ")
    print("| |               (_)    |__ \   / /        / /  \ \ ")
    print("| |     ___   __ _ _ _ __   ) | | |_   _   / / __ | |")
    print("| |    / _ \ / _` | | '_ \ / /  | | | | | / / '_ \| |")
    print("| |___| (_) | (_| | | | | |_|   | | |_| |/ /| | | | |")
    print("|______\___/ \__, |_|_| |_(_)   | |\__, /_/ |_| |_| |")
    print("              __/ |              \_\__/ |        /_/")
    print("             |___/                 |___/            ")
    print("Login? (y/n)")
    cmd = input()
    if cmd == "y" or cmd == "Y":
        open_tabs(browser)
        elapsed_time = time.time() - start_time
        print("Search Completed in " + str(elapsed_time) + "s. Script ends.")
    else:
        print("Script ends.")
Пример #11
0
def get_driver(pref):
    """If pref in `drivers` dict, return respective driver"""

    # dict[name: lambda -> WebDriver]
    drivers = dict(
        chrome=lambda: Chrome(executable_path="drivers/chromedriver"),
        firefox=lambda: Firefox(executable_path="drivers/firefoxdriver"),
        edge=lambda: Edge(executable_path="drivers/edgedriver"),
    )

    if pref in drivers:
        with suppress(WebDriverException):
            return drivers[pref]()

    raise LookupError(
        f"Driver and/or browser for driver '{pref}' does not exist")
class HeaderText(unittest.TestCase):
    def setUp(self):
        options = EdgeOptions()
        options.use_chromium = True
        options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe"
        dir = os.path.dirname(os.path.realpath(__file__))
        edge_driver_path = dir + "\\edgedriver_win64\\msedgedriver.exe"
        self.service = Service(edge_driver_path)
        self.service.start()
        self.driver = Edge(options=options, service=self.service)
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
        self.driver.get("http://localhost:4200")

    def test_HeaderText(self):
        headerText = self.driver.find_element(By.CSS_SELECTOR,
                                              "h1").get_attribute("innerText")
        self.assertEqual("todos", headerText)

    def tearDown(self):
        self.driver.quit()
        self.service.stop()
Пример #13
0
class Nawoka:
    driver = Edge(executable_path=PATH)

    def __init__(self):
        url = 'https://nawoka.fr/shop/collections/sacs/'
        self.driver.get(url)

    def check_tunnel(self):
        # Check that we can click on a given product
        WebDriverWait(self.driver, 4000).until(
            expected_conditions.element_to_be_clickable(
                (By.ID, 'btn_product_details')))
        self.driver.find_element_by_id('btn_product_details').click()
        # Check that we can add an item to the cart,
        # and that we can access the cart for checkout
        WebDriverWait(self.driver, 2000).until(
            expected_conditions.element_to_be_clickable(
                (By.ID, 'btn_add_to_cart')))
        self.driver.find_element_by_id('btn_add_to_cart').click()
        time.sleep(3)
        self.driver.find_element_by_id('link_cart').click()
        # driver.quit()

    def check_products_links(self, path=None):
        truth_array = []
        errors = []
        links = self.driver.find_elements_by_id('btn_product_details')
        WebDriverWait(self.driver, 3000).until(expected_conditions\
                    .presence_of_all_elements_located((By.ID, 'btn_product_details')))
        for link in links:
            try:
                # link.click()
                path = link.get_attribute('href')
                self.driver.get(path)
            except Exception:
                # errors.append(link.current_url())
                truth_array.append(False)
            else:
                truth_array.append(True)
                self.driver.back()
                # self.driver.execute_script('window.history.go(-1)')
                WebDriverWait(self.driver, 3000).until(expected_conditions\
                            .presence_of_all_elements_located((By.ID, 'btn_product_details')))
        # self.driver.quit()
        return all(truth_array)
Пример #14
0
 def _open_browser(self, browser_name):
     """
     :return: webdriver
     """
     if browser_name == 'chrome':
         if self.options is not None:
             self.driver = Chrome(chrome_options=self.options)
         else:
             self.driver = Chrome()
     elif browser_name == 'ie':
         self.driver = Ie()
     elif browser_name == 'safari':
         self.driver = Safari()
     elif browser_name == 'edge':
         self.driver = Edge()
     elif browser_name == 'firefox':
         self.driver = Firefox()
     else:
         raise Exception('Faild input browser name')
     self.driver.get(self.base_url)
     return self.driver
Пример #15
0
def spider_hero():
    url = "https://pvp.qq.com/web201605/herolist.shtml"
    browser = Edge(
        executable_path=
        'C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe')
    browser.get(url)
    ls = browser.find_elements_by_css_selector(
        "body > div.wrapper > div > div > div.herolist-box > div.herolist-content > ul > li"
    )
    hero_name = []
    for i in ls:
        hero_name.append(i.text)

    browser.close()

    with open("hero_name.txt", 'w', encoding="utf-8") as f:
        for i in hero_name:
            f.write(i)
            f.write('\n')

    print("写入完毕")
Пример #16
0
def spider_equipment():
    url = "https://pvp.qq.com/web201605/item.shtml"
    browser = Edge(
        executable_path=
        'C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe')
    browser.get(url)
    ls = browser.find_elements_by_css_selector("#Jlist-details > li")
    equip_name = []
    for i in ls:
        equip_name.append(i.text)

    browser.close()

    with open("equipment_name.txt", 'w', encoding="utf-8") as f:
        for i in equip_name:
            f.write(i)
            f.write('\n')

    print("写入完毕")


# spider_hero()
# spider_equipment()
Пример #17
0
from selenium.webdriver import Edge
from selenium.webdriver.common.by import By

driver = Edge()
driver.get('https://dev-login.accountantsoffice.com/login?firmCode=&returnurl=https://dev.accountantsoffice.com/Aocommon/account/login')

#Input Cred In Text Fields
firmCodeField = driver.find_element_by_css_selector('#FirmCode').send_keys('ultimate59')
# firmCodeField.send_keys('ultimate59')
userNameField = driver.find_element_by_css_selector('#UserName')
userNameField.clear()
userNameField.send_keys('amitt')

passwordField = driver.find_element_by_css_selector('#Password')
passwordField.clear()
passwordField.send_keys('Simae@678')

# #Click Login Button
userNameField.submit()

driver.find_element_by_xpath('//*[@id="pageContent"]/div/div/div[1]/div[1]/a[4]').click()
# clickPayroll = driver.find_element(by=By.XPATH, value="//a[@href='/AoCommon/Home/Launch/payroll']")
# clickPayroll.click()
# Client Text Search #select2-SelectMain-container
searchEmployer = driver.find_element_by_css_selector('#select2-SelectMain-container')
searchEmployer.click()
Пример #18
0
db = pymysql.connect(host='115.159.41.241',
                     user='******',
                     password='******',
                     port=3306,
                     db='db211814405')
cursor = db.cursor()

sql = 'CREATE TABLE IF NOT EXISTS books(' \
      'ID int(20) NOT NULL, ' \
      '书名 VARCHAR(255), ' \
      '价格 VARCHAR(255) ,' \
      '出版社 VARCHAR(255),' \
      'PRIMARY KEY(ID))'
cursor.execute(sql)

web = Edge(executable_path="M.exe")
html = web.get(url)
time.sleep(1)
web.find_element_by_xpath(
    '//*[@id="J_filter"]/div[1]/div[1]/a[2]').click()  # 点击销量排序
# web.find_elements_by_class_name('fs-tit').click
time.sleep(1)

# for i in range(1000,20000,1000):
#     js = "var q=document.documentElement.scrollTop={}".format(i)
#     web.execute_script(js)
#     time.sleep(1)
#
# web.execute_script("document.documentElement.scrollTop=0")

goods = web.find_elements_by_class_name('gl-warp > li')
Пример #19
0
def getcomponies():
    """
    Get Companies from web and write to excel file
    :return:
    """
    _bases.kill_web_driver_edge()
    driver = Edge()
    componies = []
    driver.get('https://www.dosab.org.tr/Alfabetik-Firmalar-Listesi')

    # Get links
    # links = []
    # datalinks = driver.find_elements(By.XPATH, '/html/body/div[2]/div/ul/li/div/a')
    # for link in datalinks:
    #     linkobj = {
    #         'link': link.get_attribute('href'),
    #         'name': link.text
    #     }
    #     links.append(linkobj)

    # Downlaod Mail Images
    # for complink in componies:
    #     parsedlink = str(complink['link']).split('/')
    #     mailimg = f'https://www.dosab.org.tr/dosyalar/emailler/{parsedlink[4]}_EMail.jpg'
    #     wget.download(mailimg, "imgs")

    # OCR Image to text
    pytesseract.pytesseract.tesseract_cmd = r'C:\Users\abdul\AppData\Local\Tesseract-OCR\tesseract.exe'
    imgfiles = os.listdir('imgs')
    imgfiles.sort()

    for imgfile in imgfiles:
        compid = imgfile.split('_EMail.jpg')[0]
        driver.get(f'https://www.dosab.org.tr/Firma/{compid}')
        compname = driver.find_element(By.XPATH,
                                       '/html/body/div[2]/div/div[2]/h4').text
        img = cv2.imread(f'imgs/{imgfile}')
        emailtext = str(pytesseract.image_to_string(img, lang='eng')).replace(
            '\n\f', '')

        if '@' not in emailtext:
            emailtext = ''

        company = {'mail': emailtext, 'name': compname}
        componies.append(company)

    workbook = Workbook(excel_file_name)
    worksheet = workbook.add_worksheet('dosab')
    row = 0
    hformat = workbook.add_format()
    hformat.set_bold()
    worksheet.write(row, 0, "Firma Adi", hformat)
    worksheet.write(row, 1, 'Mailler', hformat)
    row += 1

    for comp in componies:
        worksheet.write(row, 0, comp["name"])

        if '@' in comp['mail']:
            worksheet.write(row, 1, comp['mail'])
        row += 1

    workbook.close()

    driver.close()
Пример #20
0
class TestSuite_Empirix(unittest.TestCase):
    def setUp(self):
        logging.info("(Edge)## -- Entering 'setUp()' method -- ##")
        try:
            self.driver = Edge(executable_path=r'E:\Pawan\Selenium\WebAppTests_Empirix\drivers\msedgedriver.exe')
            self.driver.implicitly_wait(30)
            self.driver.maximize_window()
            self.driver.get("https://services.empirix.com/")
        except Exception as e:
            logging.exception("(Edge)Issue in func setUp() - " + str(e))
            logging.exception(traceback.format_exc())


    def waitByName(self, name):
        try:
            WebDriverWait(self.driver, 100).until(EC.presence_of_element_located((By.NAME, name)))
        except TimeoutError:
            logging.exception("(Edge)Issue in func waitByName()")
            logging.exception(traceback.format_exc())


    def waitByClass(self, classname):
        try:
            WebDriverWait(self.driver, 100).until(EC.element_to_be_clickable((By.CLASS_NAME, classname)))
        except TimeoutError:
            logging.exception("(Edge)Issue in func waitByName()")
            logging.exception(traceback.format_exc())


    def waitByXpath(self, xpath):
        try:
            WebDriverWait(self.driver, 100).until(EC.element_to_be_clickable((By.XPATH, xpath)))
        except TimeoutError:
            logging.exception("(Edge)Issue in func waitByXpath()")
            logging.exception(traceback.format_exc())


    def slow_typing(self, element, text):
        try:
            for character in text:
                element.send_keys(character)
                time.sleep(0.3)
        except Exception as e:
            logging.exception("(Edge)Issue in func slow_typing() - " + str(e))
            logging.exception(traceback.format_exc())


    def check_exists(self):
        try:
            self.driver.find_element_by_class_name('product')
        except NoSuchElementException:
            return False
        return True


    def Empirix_Login(self):
        logging.info("(Edge)## -- Entering 'Empirix_Login()' method -- ##")
        try:
            time.sleep(1)

            logging.info("(Edge)#--Located the 'username' textbox and going to slow-type username in it--")
            self.waitByName('callback_0')
            username = self.driver.find_element_by_name('callback_0')
            self.slow_typing(username, 'QA_traininguser25')
            time.sleep(1)

            logging.info("(Edge)#--Located the 'password' textbox and going to enter password into it via a file saved in system--")
            self.waitByName('callback_1')
            password = self.driver.find_element_by_name('callback_1')

            try:
                with open('password.txt', 'r') as myfile:
                    Password = myfile.read().replace('\n', '')
            except:
                Password = "******"

            self.slow_typing(password, Password)
            time.sleep(2)

            logging.info("(Edge)#--Located and going to click on the 'Sign-in' button--")
            self.waitByName('callback_2')
            signin = self.driver.find_element_by_name('callback_2')
            signin.click()

            time.sleep(30)

            logging.info("(Edge)#--Located a Cookies popup on Window and going to press 'OK'--")
            try:
                cookies = self.driver.find_element_by_class_name('cc-compliance')
                cookies.click()
                logging.info("(Edge)Cookies popup clicked successfully..")
                time.sleep(2)
            except:
                logging.exception("(Edge)Cookies popup not clicked..")

            logging.info("(Edge)Login Successful in 'Empirix' Website..")
            time.sleep(30)

        except Exception as e:
            logging.exception("(Edge)Issue in func Empirix_Login() - " + str(e))
            logging.info("(Edge)TestCase:: Logged into the 'Empirix' Website Successfully : FAIL")
            logging.exception(traceback.format_exc())
            sys.exit()


    #@unittest.skip("demonstrating skipping")
    def test_Empirix_Login(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_Empirix_Login()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            try:
                logging.info("(Edge)#--Trying locating first page after Sign-in operation--")
                res = self.check_exists()
                if res:
                    logging.info("(Edge)TestCase:: Logged into the 'Empirix' Website Successfully : PASS")
            except:
                logging.exception("(Edge)#--Trying locating 'Sign-in' button on the page even after login operation--")
                signin = self.driver.find_element_by_name('callback_2')
                if signin:
                    logging.exception("(Edge)TestCase:: Failed to login in 'Empirix' Website(Username / Password mismatch or some other issue) : FAIL")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_Empirix_Login() - " + str(e))
            logging.info("(Edge)TestCase:: Logged into the 'Empirix' Website Successfully : FAIL")
            logging.exception(traceback.format_exc())


    def switch_language_toEnglish(self):
        logging.info("(Edge)## -- Entering 'switch_language_toEnglish()' method -- ##")
        try:
            logging.info("(Edge)#--Going to click on Profile dropdown--")
            profile_dropdown = self.driver.find_element_by_link_text('QA_traininguser25(Empirix_QA_Training)')
            profile_dropdown.click()
            time.sleep(3)

            logging.info("(Edge)#--Located and going to click on the 'English' button from dropdown--")
            English = self.driver.find_element_by_xpath("//a[text()='English']")
            English.click()
            logging.info("(Edge)Clicked English button..")
            time.sleep(5)

            logging.info("(Edge)#--Switched to popup alert message to accept it--")
            obj = self.driver.switch_to.alert
            logging.info("(Edge)Before clicking Alert")
            time.sleep(2)
            obj.accept()
            logging.info("(Edge)After clicking Alert")
            time.sleep(30)
        except Exception as e:
            logging.exception("(Edge)Issue in func switch_language_toEnglish() - " + str(e))
            logging.exception("(Edge)TestCase:: Successfully switched to 'English' language(inside except) : FAIL")
            logging.exception(traceback.format_exc())
            sys.exit()


    def switch_language_toJapanese(self):
        logging.info("(Edge)## -- Entering 'switch_language_toJapanese()' method -- ##")
        try:
            logging.info("(Edge)#--Going to click on Profile dropdown--")
            profile_dropdown = self.driver.find_element_by_link_text('QA_traininguser25(Empirix_QA_Training)')
            profile_dropdown.click()
            time.sleep(3)

            logging.info("(Edge)#--Located and going to click on the 'Japanese' button from dropdown--")
            Japan = self.driver.find_element_by_xpath("//a[text()='Japanese']")
            Japan.click()
            logging.info("(Edge)Clicked Japanese..")
            time.sleep(5)

            logging.info("(Edge)#--Switched to popup alert message to accept it--")
            obj = self.driver.switch_to.alert
            logging.info("(Edge)Before clicking Alert")
            time.sleep(2)
            obj.accept()
            logging.info("(Edge)After clicking Alert")
            time.sleep(30)
        except Exception as e:
            logging.exception("(Edge)TestCase:: Successfully switched to 'Japanese' language(inside except) : FAIL")
            logging.exception("(Edge)Issue in func switch_language_toEnglish() - " + str(e))
            logging.exception(traceback.format_exc())
            sys.exit()


    @unittest.skip("Skipping English")
    def test_switch_language_toEnglish(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_switch_language_toEnglish()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            try:
                logging.info("(Edge)#--Trying locating English 'Dashboard' tab on the page--")
                dashboard_eng = self.driver.find_element_by_xpath("//a[text()='Dashboard']")
                if dashboard_eng:
                    logging.info("(Edge)TestCase:: Successfully switched to 'English' language : PASS")
            except:
                logging.exception("(Edge)#--Trying locating Japanese 'Dashboard' tab on the page(inside except)--")
                dashboard_jap = self.driver.find_element_by_xpath("//a[text()='ダッシュボード']")
                if dashboard_jap:
                    logging.exception("(Edge)Found Japanese, updating language to English")
                    self.switch_language_toEnglish()
                    try:
                        logging.exception("(Edge)#-- Again trying locating English 'Dashboard' tab on the page--")
                        dashboard_eng = self.driver.find_element_by_xpath("//a[text()='Dashboard']")
                        if dashboard_eng:
                            logging.exception("(Edge)TestCase:: Successfully switched to 'English' language : PASS")
                    except:
                        logging.exception("(Edge)TestCase:: Successfully switched to 'English' language(language not changed or Page load issue) : FAIL")

        except Exception as e:
            logging.exception("(Edge)TestCase:: Successfully switched to 'English' language(inside except) : FAIL")
            logging.exception("(Edge)Issue in func switch_language() - " + str(e))
            logging.exception(traceback.format_exc())


    @unittest.skip("Skipping English")
    def test_switch_language_toJapanese(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_switch_language_toJapanese()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            try:
                logging.info("(Edge)#--Trying locating Japanese 'Dashboard' tab on the page--")
                dashboard_jap = self.driver.find_element_by_xpath("//a[text()='ダッシュボード']")
                if dashboard_jap:
                    logging.info("(Edge)TestCase:: Successfully switched to 'Japanese' language : PASS")
            except:
                logging.exception("(Edge)#--Trying locating English 'Dashboard' tab on the page(inside except)--")
                dashboard_eng = self.driver.find_element_by_xpath("//a[text()='Dashboard']")
                if dashboard_eng:
                    logging.exception("(Edge)Found English, updating language to Japanese")
                    self.switch_language_toJapanese()
                    try:
                        logging.exception("(Edge)#-- Again trying locating Japanese 'Dashboard' tab on the page--")
                        dashboard_jap = self.driver.find_element_by_xpath("//a[text()='ダッシュボード']")
                        if dashboard_jap:
                            logging.exception("(Edge)TestCase:: Successfully switched to 'Japanese' language : PASS")
                    except:
                        logging.exception("(Edge)TestCase:: Successfully switched to 'Japanese' language(language not changed or Page load issue) : FAIL")

        except Exception as e:
            logging.exception("(Edge)TestCase:: Successfully switched to 'Japanese' language(inside except) : FAIL")
            logging.exception("(Edge)Issue in func switch_language() - " + str(e))
            logging.exception(traceback.format_exc())

    def viewTabs_English(self):
        logging.info("(Edge)## -- Entering 'viewTabs_English()' method -- ##")
        try:
            logging.info("(Edge)#--Accessing English Dashboard Tab--")

            logging.info("(Edge)# --Located and going to click on the Dashboard tab--")
            self.waitByXpath("//a[text()='Dashboard']")
            dashboard = self.driver.find_element_by_xpath("//a[text()='Dashboard']")
            dashboard.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Overall Performance' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//div[@class='col-md-3']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "dashboard_english_edge.png"))
                #self.driver.save_screenshot("dashboard_eng.png")
                logging.info("(Edge)English Dashboard accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_English(), inside Dashboard Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing English Alerts Tab--")

            logging.info("(Edge)# --Located and going to click on the Alerts tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='Alerts']")
            alerts = self.driver.find_element_by_xpath("//a[text()='Alerts']")
            alerts.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Alert Status' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//th[text()='Alert Status']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "alerts_english_edge.png"))
                #self.driver.save_screenshot("alerts_eng.png")
                logging.info("(Edge)English Alerts accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_English(), inside Alerts Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing English Tests Tab--")

            logging.info("(Edge)# --Located and going to click on the Tests tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='Tests']")
            tests = self.driver.find_element_by_xpath("//a[text()='Tests']")
            tests.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Please select a test' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//span[text()='Please select a test']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "tests_english_edge.png"))
                #self.driver.save_screenshot("tests_eng.png")
                logging.info("(Edge)English Tests accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_English(), inside Tests Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing English Variables Tab--")

            logging.info("(Edge)# --Located and going to click on the Variables tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='Variables']")
            tests = self.driver.find_element_by_xpath("//a[text()='Variables']")
            tests.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Please select a variable, or the following:' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//div[text()=' Please select a variable, or the following:']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "variables_english_edge.png"))
                #self.driver.save_screenshot("variables_eng.png")
                logging.info("(Edge)English Variables accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_English(), inside Variables Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing English Notifications Tab--")

            logging.info("(Edge)# --Located and going to click on the Notifications tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='Notifications']")
            notifications = self.driver.find_element_by_xpath("//a[text()='Notifications']")
            notifications.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Please select a notification' and clicked on 'test' before taking screenshot--")
            if self.driver.find_element_by_xpath("//span[text()='Please select a notification']"):
                test = self.driver.find_element_by_class_name("nav.nav-sidebar.tests.ng-binding.ng-scope")
                if test:
                    test.click()
                    time.sleep(10)
                    self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "notifications_english_edge.png"))
                    #self.driver.save_screenshot("notifications_eng.png")
                    logging.info("(Edge)English Notifications accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_English(), inside Notifications Tab - " + str(e))
            logging.exception(traceback.format_exc())


    def viewTabs_Japanese(self):
        logging.info("(Edge)## -- Entering viewTabs_Japanese() method -- ##")
        try:
            logging.info("(Edge)# --Accessing Japanese Dashboard Tab--")

            logging.info("(Edge)# --Located and going to click on the Dashboard tab--")
            self.waitByXpath("//a[text()='ダッシュボード']")
            dashboard = self.driver.find_element_by_xpath("//a[text()='ダッシュボード']")
            dashboard.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Overall Performance' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//div[@class='col-md-3']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "dashboard_japanese_edge.png"))
                #self.driver.save_screenshot("dashboard_jap.png")
                logging.info("(Edge)Japanese Dashboard accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_Japanese(), inside Dashboard Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing Japanese Alerts Tab--")

            logging.info("(Edge)# --Located and going to click on the Alerts tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='アラート']")
            alerts = self.driver.find_element_by_xpath("//a[text()='アラート']")
            alerts.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Alert Status' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//th[text()='アラートステータス']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "alerts_japanese_edge.png"))
                #self.driver.save_screenshot("alerts_jap.png")
                logging.info("(Edge)Japanese Alerts accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_Japanese(), inside Alerts Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing Japanese Tests Tab--")

            logging.info("(Edge)# --Located and going to click on the Tests tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='テスト']")
            tests = self.driver.find_element_by_xpath("//a[text()='テスト']")
            tests.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Please select a test' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//span[text()='テストを選択してください。']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "tests_japanese_edge.png"))
                #self.driver.save_screenshot("tests_jap.png")
                logging.info("(Edge)Japanese Tests accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_Japanese(), inside Tests Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing Japanese Variables Tab--")

            logging.info("(Edge)# --Located and going to click on the Variables tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='変数']")
            tests = self.driver.find_element_by_xpath("//a[text()='変数']")
            tests.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Please select a variable, or the following:' on the page before taking screenshot--")
            if self.driver.find_element_by_xpath("//div[text()='変数を選択してください。または、以下のように操作してください。']"):
                self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "variables_japanese_edge.png"))
                #self.driver.save_screenshot("variables_jap.png")
                logging.info("(Edge)Japanese Variables accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_Japanese(), inside Variables Tab - " + str(e))
            logging.exception(traceback.format_exc())

        try:
            logging.info("(Edge)# --Accessing Japanese Notifications Tab--")

            logging.info("(Edge)# --Located and going to click on the Notifications tab--")
            time.sleep(3)
            self.waitByXpath("//a[text()='通知']")
            notifications = self.driver.find_element_by_xpath("//a[text()='通知']")
            notifications.click()
            time.sleep(10)

            logging.info("(Edge)# --Locating a heading 'Please select a notification' and clicked on 'test' before taking screenshot--")
            if self.driver.find_element_by_xpath("//span[text()='通知を選択してください。']"):
                test = self.driver.find_element_by_class_name("nav.nav-sidebar.tests.ng-binding.ng-scope")
                if test:
                    test.click()
                    time.sleep(10)
                    self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "notifications_japanese_edge.png"))
                    #self.driver.save_screenshot("notifications_jap.png")
                    logging.info("(Edge)Japanese Notifications accessed and captured an Image of it..")

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_Japanese(), inside Notifications Tab - " + str(e))
            logging.exception(traceback.format_exc())


    @unittest.skip("Skipping English")
    def test_viewTabs_English(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_viewTabs_English()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            try:
                logging.info("(Edge)#--Trying to locate English 'Dashboard' tab on the page")
                dashboard_eng = self.driver.find_element_by_xpath("//a[text()='Dashboard']")
                if dashboard_eng:
                    self.viewTabs_English()
            except:
                logging.exception("(Edge)#--Trying to locate Japanese 'Dashboard' tab on the page(inside except)")
                dashboard_jap = self.driver.find_element_by_xpath("//a[text()='ダッシュボード']")
                if dashboard_jap:
                    logging.exception("(Edge)#--Found Japanese, updating language to English")
                    self.switch_language_toEnglish()
                    self.viewTabs_English()

        except Exception as e:
            logging.exception("(Edge)Issue in func test_viewTabs_English() - " + str(e))
            logging.exception(traceback.format_exc())


    @unittest.skip("Skipping japanese")
    def test_viewTabs_Japanese(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_viewTabs_Japanese()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            try:
                logging.info("(Edge)#--Trying to locate Japanese 'Dashboard' tab on the page")
                dashboard_jap = self.driver.find_element_by_xpath("//a[text()='ダッシュボード']")
                if dashboard_jap:
                    self.viewTabs_Japanese()
            except:
                logging.exception("(Edge)#--Trying to locate English 'Dashboard' tab on the page(inside except)")
                dashboard_eng = self.driver.find_element_by_xpath("//a[text()='Dashboard']")
                if dashboard_eng:
                    logging.exception("(Edge)#--Found English, updating language to Japanese")
                    self.switch_language_toJapanese()
                    self.viewTabs_Japanese()

        except Exception as e:
            logging.exception("(Edge)Issue in func viewTabs_Japanese() - " + str(e))
            logging.exception(traceback.format_exc())


    @unittest.skip("Skipping English")
    def test_clientInfo_check_english(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_clientInfo_check_english()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            logging.info("(Edge)# --Going to click on Profile dropdown--")
            profile_dropdown = self.driver.find_element_by_link_text('QA_traininguser25(Empirix_QA_Training)')
            profile_dropdown.click()
            time.sleep(5)

            try:
                logging.info("(Edge)# --Going to click on English 'Client' from the dropdown menu--")
                client_eng = self.driver.find_element_by_xpath("//span[text()='Client']")
                if client_eng:
                    client_eng.click()
                    time.sleep(10)
                    logging.info("(Edge)# --Locating a heading 'Client Details' in English on the page before taking screenshot--")
                    if self.driver.find_element_by_class_name('panel-title'):
                        self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "client_details_english_edge.png"))
                        #self.driver.save_screenshot("client_details_eng.png")
                        logging.info("(Edge)Client Details accessed in English and captured an Image of it..")
                        logging.info("(Edge)TestCase:: Client Details accessed in 'English' Successfully : PASS")
            except:
                logging.exception("(Edge)# --Checking for a Japanese 'Client' from the dropdown menu(inside except)--")
                client_jap = self.driver.find_element_by_xpath("//span[text()='クライアント']")
                if client_jap:
                    profile_dropdown.click()
                    time.sleep(5)
                    logging.exception("(Edge)#--Found Japanese, updating language to English")
                    self.switch_language_toEnglish()
                    try:
                        profile_dropdown = self.driver.find_element_by_link_text('QA_traininguser25(Empirix_QA_Training)')
                        if profile_dropdown:
                            profile_dropdown.click()
                            time.sleep(3)
                            logging.exception("(Edge)# --Going to click on English 'Client' from the dropdown menu once language is changed--")
                            client_eng = self.driver.find_element_by_xpath("//span[text()='Client']")
                            if client_eng:
                                client_eng.click()
                                time.sleep(10)
                                logging.exception("(Edge)# --Locating a heading 'Client Details' in English on the page before taking screenshot--")
                                if self.driver.find_element_by_class_name('panel-title'):
                                    self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "client_details_english_edge.png"))
                                    #self.driver.save_screenshot("client_details_eng.png")
                                    logging.exception("(Edge)Client Details accessed in English and captured an Image of it..")
                                    logging.exception("(Edge)TestCase:: Client Details accessed in 'English' Successfully : PASS")
                    except:
                        logging.exception("(Edge)TestCase:: Client Details accessed in 'English' Successfully(language not changed or Page load issue) : FAIL")

        except Exception as e:
            logging.exception("(Edge)TestCase:: Client Details accessed in 'English' Successfully(inside except) : FAIL")
            logging.exception("(Edge)Issue in func test_clientInfo_check_english() - " + str(e))
            logging.exception(traceback.format_exc())


    @unittest.skip("Skipping japanese")
    def test_clientInfo_check_japanese(self):
        logging.info("(Edge)## -- Entering TestCase method 'test_clientInfo_check_japanese()' -- ##")
        try:
            self.Empirix_Login()
            time.sleep(2)

            logging.info("(Edge)# --Going to click on Profile dropdown--")
            profile_dropdown = self.driver.find_element_by_link_text('QA_traininguser25(Empirix_QA_Training)')
            profile_dropdown.click()
            time.sleep(3)

            try:
                logging.info("(Edge)# --Going to click on Japanese 'Client' from the dropdown menu--")
                client_jap = self.driver.find_element_by_xpath("//span[text()='クライアント']")
                if client_jap:
                    client_jap.click()
                    time.sleep(10)
                    logging.info("(Edge)# --Locating a heading 'Client Details' in Japanese on the page before taking screenshot--")
                    if self.driver.find_element_by_class_name('panel-title'):
                        self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "client_details_japanese_edge.png"))
                        #self.driver.save_screenshot("client_details_jap.png")
                        logging.info("(Edge)Client Details accessed in Japanese and captured an Image of it..")
                        logging.info("(Edge)TestCase:: Client Details accessed in 'Japanese' Successfully : PASS")
            except:
                logging.exception("(Edge)# --Checking for a English 'Client' from the dropdown menu(inside except)--")
                client_eng = self.driver.find_element_by_xpath("//span[text()='Client']")
                if client_eng:
                    profile_dropdown.click()
                    time.sleep(3)
                    logging.exception("(Edge)#--Found English, updating language to Japanese")
                    self.switch_language_toJapanese()
                    try:
                        profile_dropdown = self.driver.find_element_by_link_text('QA_traininguser25(Empirix_QA_Training)')
                        if profile_dropdown:
                            profile_dropdown.click()
                            time.sleep(3)
                            logging.exception("(Edge)# --Going to click on Japanese 'Client' from the dropdown menu once language is changed--")
                            client_jap = self.driver.find_element_by_xpath("//span[text()='クライアント']")
                            if client_jap:
                                client_jap.click()
                                time.sleep(10)
                                logging.exception("(Edge)# --Locating a heading 'Client Details' in Japanese on the page before taking screenshot--")
                                if self.driver.find_element_by_class_name('panel-title'):
                                    self.driver.save_screenshot(os.path.join(os.getcwd(), "Images", "client_details_japanese_edge.png"))
                                    #self.driver.save_screenshot("client_details_jap.png")
                                    logging.exception("(Edge)Client Details accessed in Japanese and captured an Image of it..")
                                    logging.exception("(Edge)TestCase:: Client Details accessed in 'Japanese' Successfully : PASS")
                    except:
                        logging.exception("(Edge)TestCase:: Client Details accessed in 'Japanese' Successfully(language not changed or Page load issue) : FAIL")

        except Exception as e:
            logging.exception("(Edge)TestCase:: Client Details accessed in 'Japanese' Successfully(inside except) : FAIL")
            logging.exception("(Edge)Issue in func test_clientInfo_check_japanese() - " + str(e))
            logging.exception(traceback.format_exc())

    def tearDown(self):
        logging.info("(Edge)## -- Entering tearDown() method -- ##")
        try:
            self.driver.quit()
        except Exception as e:
            logging.exception("(Edge)Issue in func tearDown() - " + str(e))
            logging.exception(traceback.format_exc())
Пример #21
0
def selenium_parser(url, xpath, url_suffix=None):
    """
    Selenium pages by retrieving the links to each team roster
    in the menu dropdown
    """
    # driver = Edge(executable_path='C:\\Users\\Pende\\Documents\\edge_driver\\msedgedriver.exe')
    driver = Edge(executable_path=os.environ.get('EDGE_DRIVER'))
    driver.get(url)

    time.sleep(2)

    nav_ul = driver.find_element_by_xpath(xpath)
    links = nav_ul.find_elements_by_tag_name('a')

    list_of_urls = []

    for index, link in enumerate(links):
        country = f'NOCOUNTRY{index}'
        href = link.get_attribute('href')

        if '/en/volleyball' in href:
            is_match = re.search(r'\/teams\/(\w+)\-(.*)', href)
            if is_match:
                country = is_match.group(1).upper()

        if 'Teams.asp' in href \
                or 'Team=' in href \
                    or '/Teams/' in href:
            is_match = re.search(r'Team\=(.*)', href)
            if is_match:
                country = is_match.group(1)

        if '/competions/teams/' in href:
            is_match = re.search(r'teams\/(\w+)(?=\-|\s+)', href)
            if is_match:
                country = is_match.group(1).capitalize()

        if url_suffix:
            href = f'{href}/{url_suffix}'
        list_of_urls.append((href, country))

    list_of_urls = list(set(list_of_urls))

    async def writer(output_path, html):
        with open(output_path, 'w') as f:
            try:
                f.write(html)
            except:
                return False
            print(f'Writing file to {output_path}')
            asyncio.sleep(1)

    async def main(output_path, html):
        return await writer(output_path, html)

    for list_of_url in list_of_urls:
        driver.get(list_of_url[0])
        # We just retrieve the body for
        # simplification instead of taking
        # the full HTML tag
        body = driver.find_element_by_tag_name('body')

        output_path = os.path.join(PAGES_PATH, 'temp',
                                   f'{list_of_url[1]}.html')
        html = body.get_attribute('innerHTML')

        asyncio.run(main(output_path, html))
Пример #22
0
class SeleniumRuntime:
    """
    This class works like a singleton containing a single instance of the browser environment

    Attributes:
        logger: logger instance gathered from logging module, acts like a singleton
    """
    def __init__(self):
        self.logger = logging.getLogger(LOGGER_INSTANCE)

        if TARGET_BROWSER == 'chrome':
            self.browser = Chrome()
        elif TARGET_BROWSER == 'firefox':
            self.browser = Firefox()
        elif TARGET_BROWSER == 'edge':
            self.browser = Edge()

    def go_to_page(self, url):
        self.browser.get(url)

    def submit_form(self):
        form = self.browser.find_element_by_tag_name('form')
        form.submit()

    def fill_form(self, table):
        for field, value in table.items():
            element = self.browser.find_element_by_id(field)
            element.clear()
            element.send_keys(value)

    def fill_selects(self, table):
        for field_name, field_value in table.items():
            self.wait_for_element(field_value, By.XPATH).click()

    def click(self, value, by=By.ID):
        element = self.browser.find_element(by, value)
        element.click()

    def get_element(self, value, by=By.ID):
        return self.browser.find_element(by, value)

    def get_elements(self, value, by=By.ID):
        return self.browser.find_elements(by, value)

    def assert_presence(self, value, by=By.ID):
        try:
            self.browser.find_element(by, value)
            return True
        except NoSuchElementException:
            return False

    def back(self):
        self.browser.back()

    def forward(self):
        self.browser.forward()

    def refresh(self):
        self.browser.refresh()

    def current_title(self):
        return self.browser.title

    def current_url(self):
        return self.browser.current_url

    def wait_for_element(self, value, by=By.ID, timeout=30):
        return WebDriverWait(self.browser, timeout).until(
            expected_conditions.presence_of_element_located((by, value)))

    def wait_for_redirect(self, target_url, timeout=30):
        return WebDriverWait(self.browser, timeout).until(
            expected_conditions.url_to_be(target_url))

    @staticmethod
    def assert_class(element, class_name):
        class_attr = element.get_attribute('class')
        return class_attr.find(class_name) >= 0

    @staticmethod
    def assert_attribute(element, attribute_name, attribute_value):
        attr_value = element.get_attribute(attribute_name)
        return attr_value.find(attribute_value) >= 0
Пример #23
0
from selenium.webdriver import Edge


EXECUTABLE_PATH = 'C:\\Users\\Pende\\Downloads\\edgedriver_win64\\msedgedriver.exe'

DRIVER = Edge(executable_path=EXECUTABLE_PATH)
from selenium.webdriver import Edge
import time
from bs4 import BeautifulSoup

driver = Edge(
    'C:\\Users\\cakarst\\IdeaProjects\\Documentation Web Scrapping\\msedgedriver.exe'
)
driver.get(
    'https://docs.microsoft.com//en-us//sql//t-sql//data-types//date-transact-sql?view=sql-server-ver15'
)

left_nav_buttons = driver.find_elements_by_class_name('tree-item')


def click_buttons(buttonList):
    for x in range(len(buttonList)):
        if buttonList[x].is_displayed() and buttonList[x].get_attribute(
                'aria-expanded') == "false":
            driver.execute_script(
                "arguments[0].click();",
                buttonList[x].find_element_by_class_name('tree-expander'))
            child_list = buttonList[x].find_elements_by_class_name('tree-item')
            click_buttons(child_list)
            time.sleep(.01)


#######################################################
click_buttons(left_nav_buttons)

bs = BeautifulSoup(driver.page_source, 'html.parser')
for link in bs.find_all(class_="tree-item is-leaf"):
Пример #25
0
from selenium.webdriver import Edge
from selenium.webdriver import Firefox
#edge = Edge(executable_path=r"C:\Users\U112918\Downloads\MicrosoftWebDriver.exe")
driver = Edge()

driver.get("http://www.wykop.pl")
element = driver.find_element_by_partial_link_text(
    "kompresja"
)  # Lapie tylko tytul linka, nie href#<a title="1K17 Kompresja - radziecki pojazd uzbrojony w lasery" href="https://www.wykop.pl/link/3816569/1k17-kompresja-radziecki-pojazd-uzbrojony-w-lasery/">1K17 Kompresja - radziecki pojazd uzbrojony w lasery</a>
element.click()

assert "Radziecki" in driver.title
Пример #26
0
class Bumble(ImageMixin):
    matched_users = deque()
    users = deque()

    def __init__(self):
        self.driver = Edge(executable_path=os.environ.get('EDGE_DRIVER'))
        self.driver.get('https://bumble.com')

    def login(self, username, password):
        time.sleep(5)

        try:
            login_button = self.driver.find_element_by_xpath(
                '//*[@id="page"]/div/div/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/div[2]/a'
            )
        except:
            print('Could not connect.')
            return False
        else:
            login_button.click()

        time.sleep(10)

        # Facebook login
        facebook = self.driver.find_element_by_xpath(
            '//*[@id="main"]/div/div[1]/div[2]/main/div/div[2]/form/div[1]/div/div[2]/div'
        )
        facebook.click()

        time.sleep(5)

        base_window = self.driver.window_handles[0]
        self.driver.switch_to.window(self.driver.window_handles[1])

        username_field = self.driver.find_element_by_xpath('//*[@id="email"]')
        password_field = self.driver.find_element_by_xpath('//*[@id="pass"]')

        username_field.send_keys(username)
        password_field.send_keys(password)

        login_button = self.driver.find_element_by_xpath('//*[@id="u_0_0"]')
        login_button.click()

        self.driver.switch_to.window(base_window)

        time.sleep(5)

        return True

    def like(self):
        self.user_profile()
        self.driver.find_element_by_tag_name('body').send_keys(
            Keys.ARROW_RIGHT)
        time.sleep(3)
        return True

    def dislike(self):
        self.driver.find_element_by_tag_name('body').send_keys(Keys.ARROW_LEFT)
        time.sleep(3)
        return True

    def auto_swipe(self, n=10):
        for _ in range(1, n):
            self.like()
        return self.matched_users

    def user_profile(self):
        name_and_age = self.driver.find_element_by_xpath(
            '//*[@id="main"]/div/div[1]/main/div[2]/div/div/span/div[1]/article/div[1]/div[1]/article/div[2]/section/header/h1'
        )
        image = self.driver.find_element_by_xpath(
            '//*[@id="main"]/div/div[1]/main/div[2]/div/div/span/div[1]/article/div[1]/div[1]/article/div[1]/figure/picture/img'
        )
        user = name_and_age.text, image.get_attribute('src')
        if user:
            self.users.append(user)
            time.sleep(1)
            return True
        time.sleep(1)
        return False
Пример #27
0
def get_driver():
    global driver
    if not driver:
        driver = Edge()
        driver.implicitly_wait(5)
    return driver()
Пример #28
0
def open_browser(executable_path="msedgedriver",
                 edge_args=None,
                 desired_capabilities=None,
                 **kwargs):
    """Open Edge browser instance and cache the driver.

    Parameters
    ----------
    executable_path : str (Default "msedgedriver")
        path to the executable. If the default is used it assumes the
        executable is in the $PATH.
    port : int (Default 0)
        port you would like the service to run, if left as 0, a free port will
        be found.
    desired_capabilities : dict (Default None)
        Dictionary object with non-browser specific capabilities only, such as
        "proxy" or "loggingPref".
    chrome_args : Optional arguments to modify browser settings
    """
    options = Options()
    options.use_chromium = True

    # Gets rid of Devtools listening .... printing
    # other non-sensical error messages
    options.add_experimental_option('excludeSwitches', ['enable-logging'])

    if platform.system().lower() == "windows":
        options.set_capability("platform", "WINDOWS")

    if platform.system().lower() == "linux":
        options.set_capability("platform", "LINUX")

    if platform.system().lower() == "darwin":
        options.set_capability("platform", "MAC")

    # If user wants to re-use existing browser session then
    # he/she has to set variable BROWSER_REUSE_ENABLED to True.
    # If enabled, then web driver connection details are written
    # to an argument file. This file enables re-use of the current
    # chrome session.
    #
    # When variables BROWSER_SESSION_ID and BROWSER_EXECUTOR_URL are
    # set from argument file, then OpenBrowser will use those
    # parameters instead of opening new chrome session.
    # New Remote Web Driver is created in headless mode.
    edge_path = kwargs.get(
        'edge_path', None) or BuiltIn().get_variable_value('${EDGE_PATH}')
    if edge_path:
        options.binary_location = edge_path

    if user.is_root() or user.is_docker():
        options.add_argument("no-sandbox")
    if edge_args:
        if any('--headless' in _.lower() for _ in edge_args):
            CONFIG.set_value('Headless', True)
        for item in edge_args:
            options.add_argument(item.lstrip())
    options.add_argument("start-maximized")
    options.add_argument("--disable-notifications")
    if 'headless' in kwargs:
        CONFIG.set_value('Headless', True)
        options.add_argument("--headless")
    if 'prefs' in kwargs:
        if isinstance(kwargs.get('prefs'), dict):
            prefs = kwargs.get('prefs')
        else:
            prefs = util.prefs_to_dict(kwargs.get('prefs').strip())
        options.add_experimental_option('prefs', prefs)
        logger.warn("prefs: {}".format(prefs))
    driver = Edge(BuiltIn().get_variable_value('${EDGEDRIVER_PATH}')
                  or executable_path,
                  options=options,
                  capabilities=desired_capabilities)
    browser.cache_browser(driver)
    return driver
Пример #29
0
 def __init__(self):
     self.driver = Edge(executable_path=os.environ.get('EDGE_DRIVER'))
     self.driver.get('https://bumble.com')
Пример #30
0
 def setUpClass(cls):
     super().setUpClass()
     cls.web_driver = Edge()
     cls.web_driver.maximize_window()
     cls.web_driver.implicitly_wait(IMPLICIT_WAIT_TIME)