Exemplo n.º 1
0
 def login(self, url):
     # cookies = browser.get_cookies(url=self.login_url, signbot=self.bot)
     # self.session.cookies.update(cookies)
     self.session._driver = None
     if self.is_mobile:
         self.session.webdriver_options.add_experimental_option("mobileEmulation", mobile_emulation)
         driver = self.session.driver
         # 模拟触控操作
         # https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.touch_actions.html
         tap_loginbtn = TouchActions(driver)
         driver.get(url)
         user_input = driver.find_element_by_id('username')
         password_input = driver.find_element_by_id('password')
         login_btn = driver.find_element_by_id('loginBtn')
         user_input.send_keys(self.bot.user.username)
         password_input.send_keys(self.bot.user.password)
         tap_loginbtn.tap(login_btn).perform()
         time.sleep(6)
         nickname = driver.find_element_by_css_selector('#myHeader span[class$="name_text"]')
         nickname = nickname.text
         self.logger.info('登陆成功,欢迎{}'.format(nickname))
         print('登陆成功')
     else:
         self.login_pc(url)
     self.session.transfer_driver_cookies_to_session()
     self.session.driver.close()
Exemplo n.º 2
0
    def download(self, number):
        # Проверяем кол-во картинок
        assert number < 1000, "Так делать не стоит!"
        # Создаем объект для работы с окружением картинок
        touch_act = TouchActions(self.driver)

        # Берем первую картинку и нажимаем на нее
        elem = self.driver.find_element_by_class_name("rg_i")
        touch_act.tap(elem)
        touch_act.perform()

        # Выполняем процедуру сохранения
        for _ in range(number):
            pyautogui.press('apps')
            pyautogui.press('esc')
            time.sleep(1)
            pyautogui.press('apps')
            for _ in range(7):
                pyautogui.press('down')

            pyautogui.press('enter')
            time.sleep(2)
            pyautogui.press('enter')
            time.sleep(5)
            pyautogui.press('right')
    def select_timeslot(self, product):
        """
        click time slot[express delivery] and click ok for chicken
        or else select schedule quantity and cilck ok
        :param product: this variable to verify chicken or marinades

        """
        if product == "chicken":
            self.driver.implicitly_wait(19)
            self.driver.find_element_by_css_selector(self.CSS_SELECTDELIVERTTIME).click()
            time.sleep(5)
            try:
                self.driver.find_element_by_css_selector(self.CSS_EXPRESSDELIVERY).click()
            except:
                self.driver.find_element_by_css_selector(self.CSS_EXPRESSDELIVERY1).click()
            self.driver.find_element_by_css_selector(self.CSS_OK).click()
            time.sleep(7)
        elif product == "marinades":
            self.driver.implicitly_wait(19)
            torow = self.driver.find_element_by_css_selector(self.CSS_SCHEDULETOMORROW)
            action = TouchActions(self.driver)
            action.tap(torow).perform()
            time.sleep(2)
            self.driver.find_element_by_css_selector(self.CSS_SELECTDELIVERTTIME).click()
            try:
                time.sleep(2)
                self.driver.find_element_by_css_selector(self.CSS_SCHEDULEDELIVERY).click()
            except:
                self.driver.find_element_by_css_selector(self.CSS_SCHEDULEDELIVERY1).click()
            time.sleep(2)
            self.driver.find_element_by_css_selector(self.CSS_OK).click()
            time.sleep(7)
    def click(self, target, analysis=None):
        """ Implements as single tap for WinAppDriver
        
        Due to the inconsistency with Polaris touch behavior, a touch tap is actually implemented as 
        touch and hold, wait then release.
        
        If Polaris touch response if fixed, this should revert back to a simple tap call to WinAppDriver
        """

        if analysis:
            analysis('start')

        touch = TouchActions(self)
        touch.tap(target)
        touch.perform()

        if analysis:
            for i in range(1, 10):
                if not analysis('stop'):
                    touch.perform()
                else:
                    logger.warn(
                        "Trouble interacting with {0}.  Required {1} additional clicks to activate"
                        .format(target.get_attribute('AutomationId'), i))
                    return

            raise AssertionError('Unable to validate click after 10 tries')
Exemplo n.º 5
0
 def outofstock_pop(self):
     """
     check out of stock popup
     """
     WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'button#close-button')))
     popup=self.driver.find_element_by_css_selector('button#close-button')
     action = TouchActions(self.driver)
     action.tap(popup).perform()
Exemplo n.º 6
0
 def manage_payment(self):
     """
     check manage payment and visiblity of card
     """
     payment = self.driver.find_element_by_css_selector(
         self.CSS_MANAGE_PAYMENTLINK)
     action = TouchActions(self.driver)
     action.tap(payment).perform()
Exemplo n.º 7
0
 def add_card(self):
     """
     add new card
     """
     time.sleep(0.5)
     self.driver.implicitly_wait(10)
     card=self.driver.find_element_by_css_selector(self.CSS_ADDNEWCARDS)
     action = TouchActions(self.driver)
     action.tap(card).perform()
Exemplo n.º 8
0
 def click_place_order(self):
     """
     click place order button
     """
     WebDriverWait(self.driver, 20).until(
             EC.presence_of_element_located((By.CSS_SELECTOR, self.CSS_PLACEORDER)))
     placeorder = self.driver.find_element_by_css_selector(self.CSS_PLACEORDER)
     action = TouchActions(self.driver)
     action.tap(placeorder).perform()
    def click_continue(self):
        """
        click continue button

        """
        time.sleep(1)
        continuebutton = self.driver.find_element_by_css_selector(self.CSS_CONTINUE)
        action = TouchActions(self.driver)
        action.tap(continuebutton).perform()
Exemplo n.º 10
0
    def send_otp(self):
        """
        login via otp

        """
        time.sleep(0.5)
        otp = self.driver.find_element_by_css_selector(self.CSS_SENTOTP)
        action = TouchActions(self.driver)
        action.tap(otp).perform()
Exemplo n.º 11
0
    def done(self):

        time.sleep(5)
        WebDriverWait(self.driver, 25).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, self.CSS_DONE)))

        donebutton = self.driver.find_element_by_css_selector(self.CSS_DONE)
        action = TouchActions(self.driver)
        action.tap(donebutton).perform()
Exemplo n.º 12
0
    def click_view_details(self):

        WebDriverWait(self.driver, 20).until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, self.CSS_VIEWDETAILS)))
        viewdetails = self.driver.find_element_by_css_selector(
            self.CSS_VIEWDETAILS)
        action = TouchActions(self.driver)
        action.tap(viewdetails).perform()
Exemplo n.º 13
0
 def click_proceed_search(self):
     time.sleep(0.3)
     proceedbutton = self.driver.find_element_by_css_selector(
         self.CSS_PROCEED)
     action = TouchActions(self.driver)
     action.tap(proceedbutton).perform()
     WebDriverWait(self.driver, 10).until(
         EC.invisibility_of_element_located(
             (By.CSS_SELECTOR, self.CSS_LOADER)))
Exemplo n.º 14
0
 def click_addnewaddress(self):
     """
     click add new address  button
     """
     AddAddress = self.driver.find_element_by_css_selector(
         self.CSS_ADDNEWADDRESS)
     action = TouchActions(self.driver)
     action.tap(AddAddress).perform()
     time.sleep(2)
Exemplo n.º 15
0
 def click_managingaddress(self):
     """
     click managing address option
     """
     m = self.driver.find_element_by_css_selector(self.CSS_MANAGINGADDRESS)
     action = TouchActions(self.driver)
     action.tap(m).perform()
     time.sleep(2)
     self.driver.implicitly_wait(5)
Exemplo n.º 16
0
    def click_search(self):
        """
        click serach button

        """
        time.sleep(5)
        Search = self.driver.find_element_by_css_selector(self.CSS_SEARCH)
        action = TouchActions(self.driver)
        action.tap(Search).perform()
Exemplo n.º 17
0
 def click_managingprofile(self):
     """
     click managing profile option
     """
     m = self.driver.find_element_by_css_selector(self.CSS_MANAGINGPROFILE)
     action = TouchActions(self.driver)
     action.tap(m).perform()
     time.sleep(2)
     self.driver.implicitly_wait(5)
Exemplo n.º 18
0
 def test_touchaction_scrollbotton(self):
     self.driver.get("https://www.baidu.com/")
     ele = self.driver.find_element_by_id("kw")
     ele_search = self.driver.find_element_by_id("su")
     ele.send_keys("selenium测试")
     action = TouchActions(self.driver)
     action.tap(ele_search).perform()
     action.scroll_from_element(ele, 0, 10000).perform()
     sleep(3)
Exemplo n.º 19
0
 def click_continueshopping(self):
     """
     click continue shopping button
     """
     WebDriverWait(self.driver, 20).until(
         EC.visibility_of_element_located((By.CSS_SELECTOR, self.CSS_CONTINUESHOPPING1)))
     self.driver.find_element_by_css_selector(self.CSS_CONTINUESHOPPING1).is_displayed()
     continueshopping = self.driver.find_element_by_css_selector(self.CSS_CONTINUESHOPPING1)
     action = TouchActions(self.driver)
     action.tap(continueshopping).perform()
Exemplo n.º 20
0
    def click_checkout(self):
        """
        click checkout button

        """
        time.sleep(5)
        self.driver.implicitly_wait(10)
        checkout = self.driver.find_element_by_name(self.BY_NAME_CHECKOUT)
        action = TouchActions(self.driver)
        action.tap(checkout).perform()
Exemplo n.º 21
0
 def select_option(self):
     """
     select location option
     """
     time.sleep(1)
     self.driver.implicitly_wait(9)
     option = self.driver.find_element_by_css_selector(
         self.CSS_LOCATION_OPTION)
     action = TouchActions(self.driver)
     action.tap(option).perform()
Exemplo n.º 22
0
 def click_addbutton(self):
     """
     click add button
     """
     add = self.driver.find_element_by_css_selector(self.CSS_CLICK_ADD)
     action = TouchActions(self.driver)
     action.tap(add).perform()
     WebDriverWait(self.driver, 10).until(
         EC.invisibility_of_element_located(
             (By.CSS_SELECTOR, self.CSS_LOADER)))
class GoogleSearch_Page():

    def __init__(self,driver):
      self.driver=driver
      self.touchAction = TouchActions(driver)
             
    def enterSearchKeyword(self, str):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchField')
        self.driver.find_element_by_id(locator).clear()
        self.driver.find_element_by_id(locator).send_keys(str)
        
                                     
    def clickOnSearchButton(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchButton')
        self.driver.find_element_by_name(locator).click()

    def asertTextField(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchField')
        self.assertTrue(self.is_element_present(self.ByLocator(locator)))

    def assertButton(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchButton')
        self.assertTrue(self.is_element_present(By.XPATH, locator))

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def tapOnTextField(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchField')
        element = self.driver.find_element_by_id(locator)
        self.touchAction.tap(element).perform()

    def tapOnSearchButton(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchButton')
        element = self.driver.find_element_by_name(locator)
        self.touchAction.tap(element).perform()

        
    

    def waitTillElementPresent(self,id):
        for i in range(60):
            try:
                if self.is_element_present(By.ID, id): break
            except: pass
            time.sleep(1)
        else: print("unable to find element "+id+" in time")            
Exemplo n.º 24
0
 def click_edit_password(self):
     """
     to edit password
     """
     WebDriverWait(self.driver, 10).until(
         EC.visibility_of_element_located(
             (By.CSS_SELECTOR, self.CSS_EDITOPTIONPASSWORD)))
     edit = self.driver.find_element_by_css_selector(
         self.CSS_EDITOPTIONPASSWORD)
     action = TouchActions(self.driver)
     action.tap(edit).perform()
Exemplo n.º 25
0
    def click_checkout(self):
        """
        click checkout button

        """
        checkout = self.driver.find_element_by_name(self.BY_NAME_CHECKOUT)
        action = TouchActions(self.driver)
        action.tap(checkout).perform()
        WebDriverWait(self.driver, 10).until(
            EC.invisibility_of_element_located(
                (By.CSS_SELECTOR, self.CSS_LOADER)))
Exemplo n.º 26
0
 def referafriend(self):
     """
     check refer a friend link
     """
     WebDriverWait(self.driver, 10).until(
         EC.visibility_of_element_located(
             (By.CSS_SELECTOR, self.CSS_REFERAFRIENDLINK)))
     referafriendlink = self.driver.find_element_by_css_selector(
         self.CSS_REFERAFRIENDLINK)
     action = TouchActions(self.driver)
     action.tap(referafriendlink).perform()
Exemplo n.º 27
0
    def click_signup_link(self):
        """
        click signup link

        """
        WebDriverWait(self.driver, 20).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, '.or-img + a')))
        option = self.driver.find_element_by_css_selector(self.CSS_SIGNUP)
        action = TouchActions(self.driver)
        action.tap(option).perform()
        time.sleep(1)
Exemplo n.º 28
0
 def click_sendotp(self):
     """
     click send otp page
     """
     time.sleep(0.5)
     buttons = self.driver.find_elements_by_tag_name("button")
     print(len(buttons))
     for i in range(len(buttons)):
         if i == 3:
             action = TouchActions(self.driver)
             action.tap(buttons[i]).perform()
Exemplo n.º 29
0
 def rate(self):
     try:
         rate = self.driver.find_element_by_css_selector(
             "button.not-now-btn")
         action = TouchActions(self.driver)
         action.tap(rate).perform()
         Chickenimage = self.driver.find_element_by_css_selector(
             self.CSS_CHICKEN_IMAGE)
         action = TouchActions(self.driver)
         action.tap(Chickenimage).perform()
     except:
         print("")
Exemplo n.º 30
0
 def click_addbutton(self):
     """
     click add button
     """
     add = self.driver.find_element_by_css_selector(self.CSS_CLICK_ADD)
     action = TouchActions(self.driver)
     action.tap(add).perform()
     time.sleep(5)
     WebDriverWait(self.driver, 25).until(
         EC.visibility_of_element_located(
             (By.CSS_SELECTOR, self.CSS_ARROWBACK)))
     self.driver.find_element_by_css_selector(self.CSS_ARROWBACK).click()
Exemplo n.º 31
0
    def click_proceed(self):
        """
        click proceed button

        """
        time.sleep(3)
        self.driver.implicitly_wait(10)
        # proceedbutton=self.driver.find_element_by_css_selector('ion-footer.footer > tcuts-cart > ion-row#cart-proceed-button > ion-col > ion-icon.ng-tns-c3-3')

        proceedbutton = self.driver.find_element_by_name(self.BY_NAME_PROCEED)
        action = TouchActions(self.driver)
        action.tap(proceedbutton).perform()
Exemplo n.º 32
0
    def Tap_App(cls):
        log.step_normal("Element [%s]: Do Tap_App()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        element = env.driver.find_elements(cls.by, cls.value)

        actions = TouchActions(env.driver)
        actions.tap(element)
        actions.perform()

        time.sleep(3)
        cls.__clearup()