示例#1
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()
示例#2
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
示例#3
0
                     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')

j = 1
for i in goods:
    results = {}
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()
示例#5
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())
示例#6
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))
示例#7
0
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)')

download_language_selector = Select(driver.find_element_by_id('ddlLanguage'))
download_language_selector.select_by_value('1')

# Clicks button to search for driver
search_button = driver.find_element_by_xpath(
    "//a[@href='javascript: GetDriver();']")
search_button.click()
time.sleep(5)

# CLicks button to search for
download_link = driver.find_element_by_id('lnkDwnldBtn')
download_link.click()
time.sleep(5)

download_button = driver.find_element_by_xpath(
    "//a[starts-with(@href, '//us.download.nvidia.com/Windows')]")
download_button.click()
time.sleep(80)

all_files = list(os.scandir(r"C:\Users\Eric\Downloads"))
for entry in all_files:
示例#8
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