예제 #1
0
 def setup(self):
     option = webdriver.ChromeOptions()
     option.add_experimental_option('w3c', False)  # 将w3c格式屏蔽掉
     self.driver = webdriver.Chrome(options=option)
     self.action = TouchActions(self.driver)
     self.driver.maximize_window()
     self.driver.implicitly_wait(5)
 def page_scroll(self):
     _element = self.find(By.CSS_SELECTOR, ".container .type7")
     _actions = TouchActions(self._driver)
     _actions.scroll_from_element(_element, 0,
                                  3000).scroll(0, -3000).perform()
     _text = self.find(By.CSS_SELECTOR, ".l .on").text
     return _text
예제 #3
0
class TestTouchAction():
    def setup(self):
        option = webdriver.ChromeOptions()
        option.add_experimental_option('w3c', False)  # 将w3c格式屏蔽掉
        self.driver = webdriver.Chrome(options=option)
        self.action = TouchActions(self.driver)
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)

    def teardown(self):
        self.driver.quit()

    def test_touchaction_scrollbotton(self):
        """
        打开Chrome
        打开URL:http://www.baidu.com
        向搜索框输入“selenium测试”
        通过TouchAction点击搜索框
        滑动到底部,点击下一页
        关闭Chrome
        :return:
        """
        self.driver.get('http://www.baidu.com')
        ele_input = self.driver.find_element_by_id('kw')
        ele_search = self.driver.find_element_by_id('su')
        ele_input.send_keys("selenium测试")
        self.action.tap(ele_search)  # 触摸搜索按钮
        self.action.scroll_from_element(ele_input, 0,
                                        10000).perform()  # 滚动页面,添加坐标偏移量
예제 #4
0
 def swipe(self, direction):
     touch = TouchActions(self)
     touch.flick(
         self.FlickSpeeds[direction][0],
         self.FlickSpeeds[direction][1]
     )
     touch.perform()
예제 #5
0
    def test_bing_click2(self):
        self.driver.get(
            "https://cn.bing.com/search?q=henry&qs=n&form=QBLH&sp=-1&pq=henry&sc=6-5&sk=&cvid=A14643AF45204031BC59B0C3BE7DA600"
        )

        ele_keyword = self.driver.find_element_by_id("sb_form_q")

        action = TouchActions(self.driver)
        action.scroll_from_element(ele_keyword, 0, 10000).perform()
        sleep(3)
예제 #6
0
 def test_touch(self):
     self.driver.get('http://www.baidu.com')
     el = self.driver.find_element(By.XPATH, ('//*[@id="kw"]'))
     el_search = self.driver.find_element(By.XPATH, ('//*[@id="su"]'))
     el.send_keys('我是你爸爸')
     action = TouchActions(self.driver)
     action.tap(el_search)
     action.perform()
     action.scroll(0, 10000).perform()
     eltext = self.driver.find_element_by_xpath(
         '//*[@id="page"]/a[8]/span[2]')
     action.tap(eltext).perform()
예제 #7
0
    def add_member(self):
        # 为各个项sendkeys
        element = self.find(By.ID, 'username')
        element.send_keys("kongtianlong")
        self.find(By.ID, 'memberAdd_acctid').send_keys("112")
        self.find(By.ID, 'memberAdd_phone').send_keys("11111111112")

        # 下滑到底部
        touch = TouchActions(self._driver)
        touch.scroll_from_element(element, 0, 10000).perform()

        self.find(By.CSS_SELECTOR, '.js_btn_save').click()
예제 #8
0
    def add_member(self):
        self.find(*self._username).send_keys("xiaoyin")
        self.find(*self._account).send_keys("xy")
        self.find(*self._phone).send_keys("18911111111")

        # 添加一个滑动操作
        action = TouchActions(self.driver)
        action.scroll_from_element(self.driver.find_element(By.ID,"username"),0,10000).perform()
        sleep(3)

        self.find(*self._save).click()

        return ContactPage(self.driver)
예제 #9
0
def get_in_comment(driver: webdriver.Chrome):
    """
    假设已经进入电影详情
    进入电影评论页
    """
    logging.info('进入评论页')
    view_all_css = '.show-comments .view-all'  # '.show-desc-expand-btn'
    WebDriverWait(driver, global_config.time_out).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, view_all_css)))
    view_all = driver.find_element_by_css_selector(view_all_css)
    y_scale = view_all.location['y']
    driver.execute_script(f'''window.scrollTo(0, {y_scale - random.uniform(*config.random_length)})''')
    touch_action = TouchActions(driver)
    touch_action.tap(view_all).perform()
예제 #10
0
    def test_touch(self):
        self.driver.get("http://www.baidu.com")
        ele = self.driver.find_element_by_id("kw")
        ele2 = self.driver.find_element_by_id("su")
        ele.send_keys("test")

        action = TouchActions(self.driver)
        action.tap(ele2)
        action.perform()
        sleep(3)

        action.scroll_from_element(ele, 0, 10000)
        action.perform()
        sleep(3)
예제 #11
0
 def test_importcontact(self):
     self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
     action = TouchActions(self.driver)
     el = self.driver.find_element(By.CSS_SELECTOR, ".frame_logo")
     action.scroll_from_element(el, 0, 10000).perform()
     self.driver.find_element(
         By.CSS_SELECTOR,
         ".index_service_cnt_itemWrap:nth-child(2)").click()
     self.driver.find_element(
         By.CSS_SELECTOR,
         ".ww_fileImporter_fileContainer_uploadInputMask").send_keys(
             "C:/Users/zhouguoming/Desktop/datas.xlsx")
     assert "datas.xlsx" == self.driver.find_element(
         By.CSS_SELECTOR, ".ww_fileImporter_fileContainer_fileNames").text
예제 #12
0
def click(selector: str):
    if env.is_enable_mobile_emulation_mode():
        logging.info(f"Native tap on element with selector '{selector}'")
        TouchActions(driver.instance).tap(locate_element(selector)).perform()
    else:
        logging.info(f"Native click on element with selector '{selector}'")
        locate_element(selector).click()
예제 #13
0
 def test_touchaction(self):
     self.driver.get('http://www.baidu.com')
     ele = self.driver.find_element_by_id('kw')
     ele.send_keys('selenium测试')
     action = TouchActions(self.driver)
     ele_search = self.driver.find_element_by_id('su')
     action.tap(ele_search)
     action.perform()
     action.scroll_from_element(ele_search, 0, 10000).perform()
 def test_touchAction(self):
     self.driver.get("https://www.baidu.com")
     element1 = self.driver.find_element(By.ID, "kw")
     element1.send_keys("selenium测试")
     element2 = self.driver.find_element(By.ID, 'su')
     action = TouchActions(self.driver)
     action.tap(element2)
     action.scroll_from_element(element1, 0, 10000)
     action.perform()
예제 #15
0
 def test_touch_action(self):
     self.driver.get("http://www.baidu.com")
     ele=self.driver.find_element_by_id("kw").send_keys('selenium测试')
     ele_click=self.driver.find_element_by_id("su")
     action = TouchActions(self.driver)
     action.tap(ele_click)
     action.perform()
     action.scroll_from_element(ele_click,0,10000).perform()
     sleep(3)
예제 #16
0
def double_click(selector: str):
    element = locate_element(selector)
    if env.is_enable_mobile_emulation_mode():
        logging.info(f"Double tap on element with selector '{selector}'")
        TouchActions(driver.instance).double_tap(element).perform()
    else:
        logging.info(f"Double click on element with selector '{selector}'")
        ActionChains(driver.instance).double_click(element).perform()
예제 #17
0
 def test_touch(self):
     self.driver.get("https://www.baidu.com/")
     self.driver.find_element(By.XPATH,
                              "//*[@id='kw']").send_keys("selenium_3")
     ele = self.driver.find_element(By.XPATH, "//*[@id='su']")
     action = TouchActions(self.driver)
     action.tap(ele)
     action.perform()
     action.scroll_from_element(ele, 0, 10000).perform()
     sleep(3)
예제 #18
0
 def test_touch_action(self):
     self.driver.get("https://www.baidu.com/")
     ele_input = self.driver.find_element_by_id("kw")
     ele_search = self.driver.find_element_by_id("su")
     action = TouchActions(self.driver)
     ele_input.send_keys("selenium测试")
     # TouchActions的点击操作
     action.tap(ele_search)
     action.perform()
     action.scroll_from_element(ele_input, 0, 10000).perform()
예제 #19
0
 def test_grid(self):
     self.driver.get("https://www.baidu.com/")
     el = self.driver.find_element_by_id('kw')
     el_search = self.driver.find_element_by_id('su')
     el.send_keys('selenium测试')
     action = TouchActions(self.driver)
     action.tap(el_search)  # 点击
     action.perform()
     action.scroll_from_element(el, 0, 10000).perform()
     time.sleep(5)
예제 #20
0
 def test_touchaction_scrollbottom(self):
     self.driver.get("https://www.baidu.com")
     el = self.driver.find_element_by_id("kw")  #定位到输入框
     el_search = self.driver.find_element_by_id("su")  #定位到百度一下
     el.send_keys("selenium测试")  #输入
     action = TouchActions(self.driver)
     action.tap(el_search)  #点击
     action.scroll_from_element(el, 0, 10000)  #从搜索框这个元素开始向下滑动
     action.perform()
     sleep(3)
예제 #21
0
 def test_TouchAction(self):
     self.driver.get('http://www.baidu.com')
     element_input = self.driver.find_element_by_id("kw")
     element_search = self.driver.find_element_by_id("su")
     action = TouchActions(self.driver)
     element_input.send_keys("selenium测试")
     action.tap(element_search)
     action.perform()
     #将页面向下滚动,需要三个参数,
     action.scroll_from_element(element_input, 0, 10000).perform()
예제 #22
0
 def test_touchaction_scrollbotton(self):
     self.driver.get("https://www.baidu.com")
     el = self.driver.find_element_by_id("kw")
     el_search = self.driver.find_element_by_id("su")
     el.send_keys("selenium 测试")
     action = TouchActions(self.driver)
     action.tap(el_search)
     action.scroll_from_element(el, 0, 1000)
     action.perform()
     sleep(3)
예제 #23
0
 def test_touch_action(self):
     self.driver.get("https://www.baidu.com")
     self.driver.find_element(By.ID, "kw").send_keys("selenium测试")
     ele1 = self.driver.find_element(By.ID, "su")
     action = TouchActions(self.driver)
     action.tap(ele1)
     action.scroll(0, 10000)
     action.perform()
     sleep(2)
     ele2 = self.driver.find_element(By.LINK_TEXT, "下一页>").click()
     sleep(2)
예제 #24
0
    def test_touchaction(self, action=None):
        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)
        action.perform()
        #方法一
        action.scroll_from_element(ele, 0, 1000).perform()
예제 #25
0
 def test_baidu(self):
     """滑动"""
     self.driver.get("https://www.baidu.com/")
     el = self.driver.find_element_by_id("kw")
     elem = self.driver.find_element_by_id("su")
     el.send_keys("selenium")
     action = TouchActions(self.driver)
     action.tap(elem)
     action.perform()
     # 给定一个元素el,再给定一个坐标偏移量0代表横向不移动,2000代表纵向移动2000个像素位置
     action.scroll_from_element(el, 0, 2000).perform()
예제 #26
0
    def test_touch(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("bilibili")
        action = TouchActions(self.driver)
        action.tap(ele_search)
        action.perform()

        action.scroll_from_element(ele, 0, 10000).perform()
예제 #27
0
 def test_touchaction_scrollbottom(self, ):
     # 使用 TouchActions 实现界面的滑动到底端
     self.driver.get("https://www.baidu.com")
     inputele = self.driver.find_element_by_xpath('//*[@id="kw"]')
     searchele = self.driver.find_element_by_id("su")
     inputele.send_keys("username")
     action = TouchActions(self.driver)
     action.tap(searchele)
     action.perform()
     action.scroll_from_element(inputele, 0, 10000).perform()
     sleep(6)
예제 #28
0
    def test_touchaction(self):
        self.driver.get("https://www.baidu.com")
        el = self.driver.find_element(By.ID, "kw")
        el_search = self.driver.find_element(By.ID, "su")

        el.send_keys("测试")
        action = TouchActions(self.driver)
        action.tap(el_search)
        action.perform()

        action.scroll_from_element(el, 0, 10000).perform()
예제 #29
0
 def test_touchaction(self):
     self.driver.get("http://www.baidu.com")
     ele = self.driver.find_element(By.ID, "kw")
     ele.send_keys("ruby study")
     search_btn = self.driver.find_element(By.ID, "su")
     action = TouchActions(self.driver)
     action.tap(search_btn)
     sleep(5)
     action.scroll_from_element(ele, 0, 10000)
     action.perform()
     sleep(5)
예제 #30
0
 def test_case(self):
     self.driver.get("https://www.baidu.com/")
     self.driver.find_element_by_id("kw").send_keys("selenium测试")
     action_search = TouchActions(self.driver)
     action_search.tap(self.driver.find_element_by_id("su")).perform()
     el = self.driver.find_element_by_id("su")
     action = TouchActions(self.driver)
     # 向上滑动10000个像素
     action.scroll_from_element(el, 0, 10000).perform()
     self.driver.find_element_by_xpath("//*[@id='page']/div/a[10]").click()
     sleep(3)
예제 #31
0
파일: action.py 프로젝트: jine2020/test_stu
    def test_action(self):
        self.driver.get('http://www.baidu.com')
        el = self.driver.find_element(By.ID, 'kw')
        el_search = self.driver.find_element(By.ID, 'su')

        el.send_keys('selenium测试')
        action = TouchActions(self.driver)
        action.tap(el_search)
        action.perform()

        action.scroll_from_element(el, 0, 10000).perform()