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)
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()
def test_case_click(self): self.driver.get("http://www.baidu.com") element_click = self.driver.find_element(by=By.ID, value="kw") element_search = self.driver.find_element(by=By.ID, value="su") element_click.send_keys("selenium测试") action = TouchActions(self.driver) action.tap(element_click) action.perform() action.scroll(0, 10000).perform() time.sleep(2)
def scroolTo(self, xOffset, yOffset, touchActions=None, delayPerform=False): action = None if touchActions is None: action = TouchActions(self.driver) else: action = touchActions action.scroll(xOffset, yOffset) if delayPerform == False: action.perform() return action return None
def test_add_member(self): self.driver.get( "https://work.weixin.qq.com/wework_admin/loginpage_wx?") with open("cookie.yaml", encoding="UTF-8") as f: yaml_data = yaml.load(f) for cookie in yaml_data: self.driver.add_cookie(cookie) self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index") self.driver.find_element(By.XPATH, '//*[@id="menu_contacts"]').click() self.driver.find_element(By.XPATH, '//*[@class="ww_operationBar"]') self.driver.find_element(By.XPATH, '//*[@class="ww_operationBar"]/a').click() sleep(1) ast = self.driver.find_element( By.XPATH, '//*[@class="qui_btn ww_btn ww_btn_Blue js_btn_continue"]').text assert (ast == "保存并继续添加") self.driver.find_element(By.XPATH, '//*[@id="username"]').send_keys("test04") self.driver.find_element( By.XPATH, '//*[@id="memberAdd_english_name"]').send_keys("测试人员04") self.driver.find_element( By.XPATH, '//*[@id="memberAdd_acctid"]').send_keys("test034") self.driver.execute_script( 'a = document.getElementsByName("gender"),a[0].removeAttribute("checked"),a[1].setAttribute("checked","checked")' ) # print(self.driver.find_element(By.XPATH, '//*[@class="ww_radio"]').get_attribute("value")) self.driver.find_element( By.XPATH, '//*[@id="memberAdd_phone"]').send_keys("13800000004") action = TouchActions(self.driver) action.scroll(0, 1000).perform() self.driver.find_element( By.XPATH, '//*[@class="qui_btn ww_btn ww_btn_Blue js_btn_continue"]').click( ) self.driver.find_element(By.XPATH, '//*[@id="username"]').text # 新增成功后,查看页面的输入框是否清空了 assert (self.driver.find_element(By.XPATH, '//*[@id="username"]').text == "") sleep(3)
def scroll(self, x=0, y=0): action = TouchActions(self.driver) action.scroll(xoffset=x, yoffset=y).perform()