Exemple #1
0
 def select_convert_to(self, value, api):
     menu = self.find_elements((By.TAG_NAME, PageLocators.convert_to_menu))
     ac(self.driver).move_to_element(menu[1]).click(menu[1]).perform()
     option = self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, self.currency(value)))) \
         if not api \
         else self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, self.code(value))))
     ac(self.driver).move_to_element(option).click(option).perform()
Exemple #2
0
    def teacher_see_student_homework(self):
        el = self.driver.find_element_by_css_selector(
            '.main-menu>ul>li:nth-of-type(2)')
        ac(self.driver).move_to_element(el).perform()

        self.driver.find_element_by_css_selector(
            'a[href="#/task_manage?tt=1"]>li').click()
        time.sleep(1)
        self.driver.find_element_by_css_selector(
            'a[ng-click="trackTask(task)"] .fa.fa-search').click()

        self.driver.find_element_by_css_selector(
            'button.btn-outlined.ng-scope').click()
        current_handle = self.driver.current_window_handle
        all_handles = self.driver.window_handles
        for i in all_handles:
            self.driver.switch_to.window(i)
            if self.driver.title == '查看作业':
                break
        all = self.driver.find_elements_by_css_selector(
            '.myCheckbox input:checked')
        questions = []
        for i in all:
            question = i.find_element_by_xpath("./..").text.strip()
            questions.append(question)
            time.sleep(1)
        return questions
Exemple #3
0
 def mousemovementclick(self, element2):
     """
     This is used to click the element after the mouse movement
     :return: nothing
     """
     ac(driver=self.driver).move_to_element(element2).click(
         element2).perform()
     return None
Exemple #4
0
 def click_remove(self, ordinal_number):
     ac(self.browser).move_to_element(
         self.find_field(ordinal_number=ordinal_number,
                         part_of_locator=self.INPUT_EMAIL)).perform()
     elem_locator = (By.XPATH,
                     self.IMG_DELETE.replace('ROW_NUMBER',
                                             str(ordinal_number + 1)))
     WebDriverWait(self.browser, 10).\
         until(ec.visibility_of_element_located(elem_locator)).click()
    def play_video(self, url):
        """
        播放视频
        :param url: 网课的URL
        :return:
        """
        print(url)
        self.wait_url_update(url)  # 切换到新的窗口

        title = self.wait_and_get_element_text(XPATH_VIDEO_TITLE)
        print("正在播放:" + title)

        try:
            work_persent = self.wait_and_get_element_text(XPATH_WATCH_PROGRESS)
        except TimeoutException:
            work_persent = "任务进度元素加载失败"  # 元素加载失败

        print("任务进度:" + work_persent)
        time.sleep(0.5)
        """该小节播放完成/不需要播放"""
        if "100%" in work_persent:
            print('该视频不需要播放,跳过')
            return
        """"需要播放视频的情况"""
        print('该视频需要播放,尝试加速播放')
        print('等待播放器加载完毕')
        self.wait_and_get_element_text(XPATH_VIDEO_PLAYER)
        """开始播放"""
        print('播放器已加载,尝试点击开始播放按钮')
        button = WebDriverWait(self.driver, 10, poll_frequency=2).until(
            ec.element_to_be_clickable((By.XPATH, XPATH_BUTTON_PLAY)))
        """设置2倍速度"""
        if button:
            print('已开始播放,尝试设置二倍速')
            speed_button = WebDriverWait(
                self.driver, 10, poll_frequency=1).until(
                    ec.presence_of_element_located(
                        (By.XPATH, XPATH_BUTTON_SELECT_PLAY_SPEED)))
            speed_2 = self.driver.find_element_by_xpath(XPATH_BUTTON_2X_SPEED)
            ac(self.driver).move_to_element(speed_button).perform()
            time.sleep(1)
            speed_2.click()
            button.click()
            print('已设置为二倍速,等待视频播放完毕……')

            to_seconds = lambda x: int(x[1]) * 60 + int(x[2])
            time_elapsed = to_seconds(
                self.driver.find_element_by_xpath(
                    XPATH_LABEL_TIME_PLAYED).text.split(':'))
            time_total = to_seconds(
                self.driver.find_element_by_xpath(
                    XPATH_LABEL_VIDEO_DURATION).text.split(':'))
            self.wait_video_play_finish(time_elapsed, time_total)
            print('视频放完啦,等几秒再看下一个')
            time.sleep(5)
Exemple #6
0
def wb():
    a = wd.Firefox()
    a.get("http://xgyw.tpzy5.com/uploadfile/201805/8/5C223025472.jpg")
    element = a.find_element_by_xpath("/html/body/img")
    action = ac(a).context_click(element)
    action.send_keys_to_element(element, "v")
    action.perform()
Exemple #7
0
def cr_pack_init(path=0, pt=0):
    expected_DB_value = s_spravoch[0][path]
    print(expected_DB_value)
    element = ms.waiting('element_to_be_clickable', 'XPATH', menu_item, 3, 0)
    hov = ac(driver).move_to_element(element)
    hov.perform()
    sleep(0.1)
    ms.waiting('element_to_be_clickable', 'XPATH', types_npa1[pt], 3,
               0).click()
    return expected_DB_value
Exemple #8
0
def simuMove(driver):
    act = ac(driver)
    button = driver.find_element_by_xpath(
        '//div[@class="geetest_slider_button"]')
    onElem = act.click_and_hold(button).perform()
    track = getTrack()
    for x in track():
        onElem.move_by_offset(x, 0).perform()
    time.sleep(.5)
    onElem.release().perform()
Exemple #9
0
    def watching_letter(self, url):
        print(url)
        wd = webdriver.Chrome()
        wd.set_page_load_timeout(10)
        wd.get("https://www.baidu.com")
        wd.delete_all_cookies()

        for i in WangKe.cookies:
            wd.add_cookie(i)
        try:
            print(1)
            wd.get(url)
            print(2)
        except:
            print(3)
            wd.execute_script("window.stop()")
        finally:
            print(4)
            time.sleep(5)
            homework_title = wd.find_element_by_xpath(
                "//span[@class='text text-ellipsis']")
            homework_text = homework_title.text
            try:
                time_persent = wd.find_element_by_xpath(
                    '//*[@id="app"]/div[2]/div[2]/div[3]/div/div[2]/div[1]/section[1]/div[2]/div/div/span'
                ).text
            except:
                time_persent = None
            finally:
                print(
                    '=============================================================================================='
                )
                print(time_persent, homework_text, wd.current_url)

                print(
                    '=============================================================================================='
                )

                if (not '随堂作业' in homework_text) and (not '100%'
                                                      in time_persent):
                    try:
                        # button = wait_wd(wd,10,poll_frequency=2).until(ec.element_to_be_clickable((By.XPATH , "//xt-playbutton[@class='xt_video_player_play_btn fl']")))
                        button = wait_wd(wd, 10, poll_frequency=2).until(
                            ec.element_to_be_clickable((
                                By.XPATH,
                                '//*[@id="video-box"]/div/xt-wrap/xt-controls/xt-inner/xt-playbutton'
                            )))
                        button_text = wd.find_element_by_xpath(
                            '//*[@id="video-box"]/div/xt-wrap/xt-controls/xt-inner/xt-playbutton/xt-tip'
                        ).text
                        print(button_text)

                        # print('button cunzai')
                        if button:
                            time.sleep(5)
                            speed_button = wait_wd(
                                wd, 10, poll_frequency=1
                            ).until(
                                ec.presence_of_element_located((
                                    By.XPATH,
                                    '//*[@id="video-box"]/div/xt-wrap/xt-controls/xt-inner/xt-speedbutton/xt-speedvalue'
                                )))
                            speed_2 = wd.find_element_by_xpath(
                                '//*[@id="video-box"]/div/xt-wrap/xt-controls/xt-inner/xt-speedbutton/xt-speedlist/ul/li[1]'
                            )
                            ac(wd).move_to_element(speed_button).perform()
                            time.sleep(1)
                            speed_2.click()
                            button.click()
                            time_ = wd.find_element_by_xpath(
                                '//*[@id="video-box"]/div/xt-wrap/xt-controls/xt-inner/xt-time/span[2]'
                            ).text.split(':')
                            time_long = (
                                (int(time_[1]) * 60 + int(time_[2])) + 30) / 2
                            print(time_long)
                            time.sleep(time_long)
                            # print('watching ',url)
                            print('----', url, '成功')
                            wd.close()
                        else:
                            # print('button 不存在')
                            wd.close()
                    except TimeoutException:
                        print('未找到 button')
                        print('-------------', url, '失败')
                        wd.close()

                else:
                    # print("100% or 作业")
                    print('close----', url)
                    wd.close()

                return 1
Exemple #10
0
 def check_private_banking_r_button(self):
     submit_button = self.find_element((By.XPATH, PageLocators.submit))
     r_button = self.find_elements((By.XPATH, PageLocators.private_banking_r_button))
     ac(self.driver).move_to_element(submit_button).move_to_element(r_button[1]).click(r_button[1]).perform()
Exemple #11
0
time.sleep(2)
# browser.execute_script("window.open('{}')".format(keka_url))
print('Opening Keka login url')
browser.get(keka_url)

while browser.current_url != keka_url:
    if browser.current_url == keka_post_login_url:
        print('Already Logged')
        break
    else:
        print('Not logged in!\nTrying to login to keka')
        if Wait_by_id('email'):
            browser.find_element_by_id('email').send_keys(kuname)
            browser.find_element_by_id('password').send_keys(kpass)
            ac(browser).send_keys(Keys.ENTER).perform()
        else:
            print('Page didn\'t load properly.\nExitting..')
            browser.quit()
            sys.exit()
        if Wait_by_id('top-nav'):
            print('Logged in')
            break
        else:
            print('Unable to login...\nExiting..')
            browser.quit()
            sys.exit()
    time.sleep(.2)

# get a reference to webclockin button and click
# Check if web clock in Successful
Exemple #12
0
    password.click()
    password.send_keys('<Enter your password>')
    password.send_keys(Keys.ENTER)

block = WebDriverWait(driver, 10).until(
    ec.element_to_be_clickable((
        By.XPATH,
        '/html/body/div/div/div/div[2]/main/div/div/div/div[1]/div/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div/div/div/div[1]/div/div/div/div[2]/div/div/div/div'
    )))
block.click()
block.send_keys(tweet)

if check == 1:
    pic = WebDriverWait(driver, 10).until(
        ec.element_to_be_clickable((
            By.XPATH,
            '/html/body/div/div/div/div[2]/main/div/div/div/div[1]/div/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[2]/div/div/div[1]/div[1]/div'
        )))
    ac(driver).move_to_element(pic).click().perform()
    time.sleep(6)

post = WebDriverWait(driver, 20).until(
    ec.element_to_be_clickable((
        By.XPATH,
        '/html/body/div/div/div/div[2]/main/div/div/div/div[1]/div/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[2]/div/div/div[2]/div[3]/div/span/span'
    )))
post.click()

time.sleep(6)
driver.quit()