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()
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
def livingly():
    url = 'https://www.livingly.com/runway/Milan+Fashion+Week+Fall+2019/Aigner/Details/browse'
    driver = Edge(executable_path=PATH)
    action_chains = ActionChains(driver)
    driver.get(url)
    WebDriverWait(driver, 5000).until(expected_conditions\
            .visibility_of_element_located((By.CLASS_NAME, 'thumbnail-strip')))
    content = driver.find_element_by_xpath('//ul[@class="thumbnail-strip"]')
    links = content.find_elements_by_tag_name('a')

    # Store the links beforehand because Selenium does
    # not update the driver with the new content
    paths = (link.get_attribute('href') for link in links)

    for path in paths:
        # link.click()
        driver.get(path)
        WebDriverWait(driver, 3000).until(expected_conditions\
                .visibility_of_element_located((By.CLASS_NAME, 'region-image')))
        try:
            slideshow = driver.find_element_by_xpath('//div[@class="slideshow-img-link"]')
        except Exception:
            driver.execute_script('window.history.go(-1);')
        else:
            if slideshow.is_displayed():
                big_image_url = slideshow.find_element_by_tag_name('img').get_attribute('data-zoom-url')

                if big_image_url:
                    # driver.get(big_image_url)
                    driver.execute_script(f'window.open("{big_image_url}", "_blank");')

                    # This part will right click on the image,
                    # download it locally
                    image = driver.find_elements_by_tag_name('img')
                    action_chains.context_click(image).perform()

                    # This section gets all the tabs in the
                    # browser, closes the newly opened image
                    # tab and returns the previous one
                    driver.switch_to_window(driver.window_handles[1])
                    driver.close()
                    driver.switch_to_window(driver.window_handles[0])
                    # Wait a couple of seconds before returning
                    # going back in history
                    driver.execute_script('window.history.go(-1);')
                else:
                    driver.execute_script('window.history.go(-1);')
    driver.close()
Ejemplo n.º 4
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("写入完毕")
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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.")
Ejemplo n.º 8
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()
Ejemplo n.º 9
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())
Ejemplo n.º 10
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))
Ejemplo n.º 11
0
def get_componies():
    _bases.kill_web_driver_edge()
    driver = Edge()
    componies = []
    # region > info type headers variables
    sector = 'Faaliyet Alanı '
    mail = 'Epostalar '
    phone = 'Telefonlar '
    # endregion

    driver.get('http://www.kosab.org.tr/FIRMALAR/')

    # Get table rows count
    pagination_count = len(
        driver.find_elements(
            By.XPATH, '/html/body/div[2]/div/div/span[2]/table/tbody/tr'))
    pagination_links = []

    anchors = driver.find_elements(
        By.XPATH,
        f'/html/body/div[2]/div/div/span[2]/table/tbody/tr[{pagination_count}]/td/a'
    )
    for pagelink in anchors:
        pagination_links.append(pagelink.get_attribute('href'))

    for page in pagination_links:
        driver.get(page)

        def get_comps_row():
            compoinesrows = driver.find_elements(
                By.XPATH, '/html/body/div[2]/div/div/span[2]/table/tbody/tr')
            return compoinesrows

        for row in range(1, len(get_comps_row()) - 1):
            company = {}
            compsrow = get_comps_row()
            compsrow[row].click()

            datatable = driver.find_elements(
                By.XPATH, '/html/body/div[2]/div/div/span[2]/table/tbody/tr')

            for cell in range(0, len(datatable) - 1):

                datastr = str(datatable[cell].text)

                if cell == 0:
                    company['Name'] = datatable[cell].text

                if datastr.startswith(sector):
                    company['Sector'] = str(
                        datatable[cell].text).split(sector)[1]

                if datastr.startswith(mail):
                    company['Mail'] = str(datatable[cell].text).split(mail)[1]

                if datastr.startswith(phone):
                    company['Tel'] = str(datatable[cell].text).split(phone)[1]

            componies.append(company)
            driver.back()

    # region > Write excel
    row = 0
    workbook = Workbook(excel_file_name)
    worksheet = workbook.add_worksheet('Kosab')

    hformat = workbook.add_format()
    hformat.set_bold()
    hformat.set_align('center')
    hformat.set_align('vcenter')
    hformat.set_font_color('white')
    hformat.set_bg_color('blue')

    worksheet.write(0, 0, 'Firma Adi', hformat)
    worksheet.write(0, 1, 'Mail Adresi', hformat)
    worksheet.write(0, 2, 'Sektor', hformat)
    worksheet.write(0, 3, 'Telefon', hformat)

    worksheet.set_column('A:A', 70)
    worksheet.set_column('B:B', 40)
    worksheet.set_column('C:C', 40)
    worksheet.set_column('D:D', 30)
    row += 1

    for cmpy in componies:

        if 'Name' in cmpy:
            worksheet.write(row, 0, str(cmpy['Name']))

        if 'Mail' in cmpy:
            worksheet.write(row, 1, str(cmpy['Mail']))

        if 'Sector' in cmpy:
            worksheet.write(row, 2, str(cmpy['Sector']))

        if 'Tel' in cmpy:
            worksheet.write(row, 3, str(cmpy['Tel']))

        row += 1

    if os.path.exists(excel_file_name):
        os.remove(excel_file_name)

    time.sleep(2)
    workbook.close()
from selenium.webdriver import Edge
from selenium.webdriver import Firefox

# edge = Edge(executable_path=r"C:\Users\U112918\Downloads\MicrosoftWebDriver.exe")
driver = Edge()

# Selenium musi miec wskazanie w jakim iFrame jest szukany element (jesli w ogole jest iFrame)

driver.get("http://igame.com/eye-test/")
driver.switch_to.frame(driver.find_element_by_tag_name("Iframe"))
element = driver.find_element_by_class_name("thechosenone")
for i in range(900):
    element = driver.find_element_by_class_name("thechosenone")
    element.click()
Ejemplo n.º 13
0
from selenium.webdriver import Edge
#from selenium.webdriver import Firefox

driver = Edge()
driver.get('www.wykop.pl/')

element = driver.find_element_by_partial_link_text('radziecki')

# element = driver.find_element_by_id("login")

element.click()
Ejemplo n.º 14
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()
Ejemplo n.º 15
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
Ejemplo n.º 16
0
# Import Dependicies
from selenium.webdriver import Edge
from selenium.webdriver.support.ui import Select
import time

import os
import shutil
# Open Edge instance for navigation
ref_time = time.time()

# driver = Edge(executable_path=r"C:\Users\Eric\Desktop\Coding Stuff\SD_Code\SD_Auto_Driver_Install\edgedriver_win64\msedgedriver.exe")
driver = Edge(executable_path=r"edgedriver_win64\msedgedriver.exe")
# Navigate to specified website
driver.get("https://www.nvidia.com/Download/index.aspx?lang=en-in")
time.sleep(5)

#This block of code sets all the dropdown menus to the correct selections
#==============================================================================================

# Store product type drop down menu as object and Select GeForce from dropdown menu
product_type_selector = Select(
    driver.find_element_by_id('selProductSeriesType'))
product_type_selector.select_by_value('1')

product_series_selector = Select(driver.find_element_by_id('selProductSeries'))
product_series_selector.select_by_visible_text('GeForce RTX 30 Series')

download_type_selector = Select(
    driver.find_element_by_id('ddlDownloadTypeCrdGrd'))
download_type_selector.select_by_visible_text('Game Ready Driver (GRD)')
Ejemplo n.º 17
0
def Iniciar():
    global driver
    os.startfile("YOUR_PATH")
    driver = Edge(executable_path='YOUR_PATH')
    driver.get("LINK")
Ejemplo n.º 18
0
from selenium.webdriver import Edge
import random
driver = Edge()



driver.get("https://www.igame.com/eye-test/")

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
score = 0
if score > 0 and score < 9:
    co_wybrac = random.randint(0, 1)
    if co_wybrac == 0
    el = driver.find_element_by_class_name("thechosenone")
el.click()

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"):
Ejemplo n.º 20
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.nosab.org.tr/firmalar/tr')
    alphabetslinks = []

    for links in driver.find_elements(By.XPATH, '//*[@id="accordion-2"]/li/a'):
        link = {
            'Sector': links.text,
            'Name': links.get_attribute('href')
        }
        alphabetslinks.append(link)

    for anchor in alphabetslinks:
        driver.get(anchor['Name'])
        companies_sector = {
            'Sector': anchor['Sector'],
            'comps': []
        }

        componies_count = len(driver.find_elements(By.XPATH, '/html/body/div[7]/div/div[2]/div[3]/ul/li/a'))

        for indx in range(1, componies_count + 1):
            comp = driver.find_element(By.XPATH, f'/html/body/div[7]/div/div[2]/div[3]/ul/li[{indx}]/a')
            comp.click()
            companies_sector['Sector'] = anchor['Sector']
            company = {
                'Name': driver.find_element(By.XPATH, '/html/body/div[7]/div/div[2]/div[1]/div').text,
                'Data': str(driver.find_element(By.XPATH, '/html/body/div[7]/div/div[2]/div[4]').text)
            }

            companies_sector['comps'].append(company)
            driver.back()

        componies.append(companies_sector)

    row = 0
    workbook = Workbook(excel_file_name)
    worksheet = workbook.add_worksheet('nosab')

    hformat = workbook.add_format()
    hformat.set_bold()
    hformat.set_align('center')
    hformat.set_align('vcenter')

    worksheet.write(row, 0, 'Firma Adi', hformat)
    worksheet.set_column('A:A', 100)

    worksheet.write(row, 1, 'Bilgileri', hformat)
    worksheet.set_column('B:B', 120)

    row += 1

    fwarp = workbook.add_format()
    fwarp.set_text_wrap()

    fname_centralize = workbook.add_format()
    fname_centralize.set_align('center')

    for company in componies:

        if 'Sector' in company:
            worksheet.write(row, 0, company['Sector'], hformat)
            row += 1

        if 'comps' in company:
            for comp in company['comps']:

                if 'Name' in comp:
                    worksheet.write(row, 0, comp['Name'], fname_centralize)

                if 'Data' in comp:
                    worksheet.write(row, 1, comp['Data'], fwarp)

                row += 1

    if os.path.exists(excel_file_name):
        os.remove(excel_file_name)

    time.sleep(_bases.timeout)
    workbook.close()
    driver.close()
Ejemplo n.º 21
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
Ejemplo n.º 22
0
        "//*[@id=\"LoginComponent\"]/form/button")
    go.click()
    cookie = driver.get_cookies()
    with open("cookies.json", "w") as target:
        json.dump(cookie, target, indent=4)


if __name__ == "__main__":
    from selenium.webdriver import edge, Edge
    import time
    import os
    # option=edge.webdriver()
    prefs = {"profile.managed_default_content_settings.images": 2}
    # option.add_argument("--headless")
    driver = Edge("./msedgedriver.exe")
    driver.get("https://www.pixiv.net/")

    if not os.path.exists("cookies.json"):
        login(driver, input("用户名"), input("密码"))

    with open("cookies.json", "r") as f:
        cookies = json.load(f)
        for cookie in cookies:
            #del cookie["domain"]
            driver.add_cookie(cookie)

        res = driver.get("https://accounts.pixiv.net/login")

        if driver.current_url != "https://www.pixiv.net/":
            login(driver, input("用户名"), input("密码"))
        # driver.refresh()
Ejemplo n.º 23
0
                     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')
Ejemplo n.º 24
0
class Tinder:
    matched_users = []

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

    def login(self, username, password):
        WebDriverWait(self.driver, 6000).until(expected_conditions \
                .element_to_be_clickable((By.XPATH, '//*[@id="modal-manager"]/div/div/div/div/div[3]/span/div[2]/button')))

        try:
            facebook = self.driver.find_element_by_xpath(
                '//*[@id="modal-manager"]/div/div/div/div/div[3]/span/div[2]/button'
            )
        except:
            print('Could not connect.')
            return False
        else:
            facebook.click()

        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(10)

        localization_button = self.driver.find_element_by_xpath(
            '//*[@id="modal-manager"]/div/div/div/div/div[3]/button[1]')
        localization_button.click()

        time.sleep(10)

        try:
            accept_to_receive_messages = self.driver.find_element_by_xpath(
                '//*[@id="modal-manager"]/div/div/div/div/div[3]/button[2]')
        except:
            print(
                'Could not find message button or message modal did not pop up.'
            )
            return False
        else:
            accept_to_receive_messages.click()

    def like(self):
        # like_button = self.driver.find_element_by_xpath('//*[@id="content"]/div/div[1]/div/main/div[1]/div/div/div[1]/div/div[2]/div[4]/button')
        # self.button_click(like_button)

        # Test for the
        # random pop screen
        # popup = self.close_random_popup()
        # if popup:
        #     popup.click()

        # time.sleep(1)

        self.driver.find_element_by_tag_name('body').send_keys(
            Keys.ARROW_RIGHT)

        time.sleep(3)

        try:
            # If we have a match, we have to
            # manage the card in question by
            # clicking on the link
            match_card_link = self.driver.find_element_by_xpath(
                '//*[@id="modal-manager-canvas"]/div/div/div[1]/div/div[3]/a')
        except:
            # There is no match, then continue
            # swiping until we find one
            return False
        else:
            match_card_link.click()
            self.matched_users.append(1)
            return True

    def dislike(self):
        dislike_button = self.driver.find_element_by_xpath(
            '//*[@id="content"]/div/div[1]/div/main/div[1]/div/div/div[1]/div/div[2]/div[2]/button'
        )
        self.button_click(dislike_button)

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

    @staticmethod
    def button_click(button):
        try:
            button.click()
        except:
            return False
        else:
            return True

    def close_random_popup(self):
        WebDriverWait(self.driver, 2000).until(
            expected_conditions.visibility_of(
                (By.XPATH, '//*[@id="modal-manager"]')))
        try:
            # Deals with the pop up that asks us
            # to add tinder to the homescreen
            home_screen_button = self.driver.find_element_by_xpath(
                '//*[@id="modal-manager"]/div/div/div[2]/button[2]')
        except:
            return False
        else:
            return home_screen_button
Ejemplo n.º 25
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
Ejemplo n.º 26
0
def get_componies():
    """
    Get Companies from web and write to excel file
    :return:
    """
    _bases.kill_web_driver_edge()
    driver = Edge()
    componies = []

    driver.get('https://bursaderiosb.com/uyeler')

    componies_data = driver.find_elements(
        By.XPATH, '//*[@id="main"]/div/div/div[2]/div')
    compscount = None

    if len(componies_data) > 0:
        compscount = len(componies_data)

    for i in range(1, compscount):
        company_anchor = driver.find_element(
            By.XPATH, f'//*[@id="main"]/div/div/div[2]/div[{i}]/div[2]/a')
        company_anchor.click()
        company = {
            'Name':
            driver.find_element(By.XPATH,
                                '//*[@id="main"]/div/div/div[1]').text,
        }
        company_data = str(
            driver.find_element(
                By.XPATH,
                '//*[@id="main"]/div/div/div[2]/div').text).split('\n')
        for compdata in company_data:

            mailstr = 'Mail:'
            if compdata.startswith(mailstr):
                company['Mail'] = compdata.split(mailstr)[1]

            phonestr = 'Telefon:'
            if compdata.startswith(phonestr):
                company['Tel'] = compdata.split(phonestr)[1]

        componies.append(company)

        driver.back()

    # region > Write to excel
    row = 0
    workbook = Workbook(excel_file_name)
    worksheet = workbook.add_worksheet('Bursa Deri OSB')

    hformat = workbook.add_format()
    hformat.set_bold()
    hformat.set_align('center')
    hformat.set_align('vcenter')

    worksheet.write(row, 0, 'Firma Adi', hformat)
    worksheet.write(row, 1, 'Mail Adresi', hformat)
    worksheet.write(row, 2, 'Telefon', hformat)

    worksheet.set_column('A:A', 100)
    worksheet.set_column('B:B', 80)
    worksheet.set_column('C:C', 50)
    row += 1

    for cmpy in componies:
        if 'Name' in cmpy:
            worksheet.write(row, 0, str(cmpy['Name']))

        if 'Mail' in cmpy:
            worksheet.write(row, 1, str(cmpy['Mail']))

        if 'Tel' in cmpy:
            worksheet.write(row, 2, str(cmpy['Tel']))

        row += 1

    if os.path.exists(excel_file_name):
        os.remove(excel_file_name)

    workbook.close()
    # endregion

    time.sleep(3)
    driver.quit()