예제 #1
0
def move(dis):
    action =  ActionChains(driver)
    action.click_and_hold(driver.find_element_by_css_selector("div.geetest_slider_button"))
    trace_list = get_trace_list(dis)
    for i in trace_list:
        action.move_by_offset(i, 0)
    action.release().perform()
예제 #2
0
    def move_slider(self, move_x):
        track = self.simulation_track(move_x - self.error)
        move_element = self.driver.find_element_by_class_name(
            'geetest_slider_button')
        action = ActionChains(self.driver)
        action.click_and_hold(move_element).perform()
        time.sleep(0.3)
        for i, x in enumerate(track):
            action.move_by_offset(x, 0).perform()
            if i < 1 / 3 * len(track):
                time.sleep(0.01)
            if i < 1 / 2 * len(track):
                time.sleep(0.02)
            elif i < 3 / 4 * len(track):
                time.sleep(0.04)
            elif i < 5 / 6 * len(track):
                time.sleep(0.08)
            else:
                time.sleep(0.1)
            action = ActionChains(self.driver)

        time.sleep(0.5)
        action.release().perform()
        time.sleep(3)
        try:
            self.driver.find_element_by_class_name('geetest_slider_button')
            return 0
        except:
            return 1
예제 #3
0
def getBlocklyElementRect(self, elementNo):
    blocklyCanvas = self.driver.find_elements_by_class_name("blocklyBlockCanvas")[1]
    piece = blocklyCanvas.find_elements_by_tag_name("rect")[elementNo]
    time.sleep(.5)
    actionChains3= ActionChains(self.driver)
    actionChains3.click_and_hold(piece).perform()
    actionChains3.move_by_offset(-20,-20).move_by_offset(270,-210).release(piece).perform()
예제 #4
0
def do_login(driver, name_pwd):
    print('=====do_login=====')
    # 切换到账号登录tab
    driver.find_element_by_xpath(
        '/html/body/div[2]/div/div/div[1]/a[2]').click()
    driver.find_element_by_id('userName').send_keys(name_pwd[0])
    driver.find_element_by_id('password').send_keys(name_pwd[1])
    # 获取活动模块
    button = driver.find_element_by_xpath(
        '//*[@id="siller1_dt_child_content_containor"]/div[3]')
    action = ActionChains(driver)
    action.click_and_hold(button).perform()

    # 滑动模块
    x = 0
    while True:
        action.move_by_offset(xoffset=x, yoffset=0).perform()
        x += 50
        print(x)
        if x >= 274:
            break

    time.sleep(1)
    action.release().perform()

    # 点击登录按钮
    driver.find_element_by_xpath('//*[@id="submit"]').click()
    time.sleep(2)
예제 #5
0
    def test_blockly_karel_transition(self):
         """
         Testing that changing Blockly will be saved in Karel code
         """
         self.driver.get(self.host + "/index.html")  
         self.driver.execute_script('window.localStorage.clear();')
         actionChains = ActionChains(self.driver)

         #going into blockly window
         rb = self.driver.find_element_by_class_name("blockly-button")
         self.assertIsNotNone(rb)
         rb.click()

        
         #selecting and draging "move" piece on to the canvas placing it into "for loop block"
         karel = self.driver.find_element_by_id(":1")
         karel.click()
       
         getBlocklyElement(self, 0)
         piece = self.driver.find_element_by_class_name("blocklySelected")
         actionChains.click_and_hold(piece).perform()
         actionChains.move_by_offset(140, 35).release(piece).perform()
        
         #back to karel
         back = self.driver.find_elements_by_class_name("btn-primary")[1]
         self.assertIsNotNone(back)
         back.click()

         #checking if code is in sync with blockly
         code = self.driver.find_element_by_class_name("CodeMirror-code")
         self.assertEqual(code.text, '1\nfrom karel import * \n2\nmove()\n3')
예제 #6
0
파일: map.py 프로젝트: 2gis/mapsapi
 def drag(self, x_offset, y_offset):
     center = self.driver.execute_script(GetScripts.getContainerCenter)
     actions = ActionChains(self.driver)
     actions.move_to_element_with_offset(self.element, int(center['x']), int(center['y']))
     actions.click_and_hold()
     actions.move_by_offset(x_offset, y_offset)
     actions.release().perform()
예제 #7
0
def run():
    selector = etree.HTML(res)
    urls = re.findall(
        r'<a onclick="utLoginInterceptor.*? href="(.*?)" target="_blank" class="ma_h1"',
        res, re.S)  # 匹配url
    try:
        print('识别出滑动界面')
        url_fail = re.findall("<script>window.location.href='(.*?)';</script>",
                              res, re.S)
        url_fail = url_fail[0]
        # driver.maximize_window()
        time.sleep(3)
        driver.get(url_fail)
        time.sleep(2)
        print('开始滑动')
        # 滑动条定位
        start = driver.find_element_by_xpath(
            '//div[@id="nc_1__scale_text"]/span')
        # 长按拖拽
        action = ActionChains(driver)
        # 长按
        action.click_and_hold(start).perform()
        # 拉动
        action.drag_and_drop_by_offset(start, 400, 0).perform()
        time.sleep(3)

    except Exception as e:
        for url in urls:
            url_new = 'https://www.qcc.com/' + url
            print(url_new)

        print('*' * 100)
예제 #8
0
def slider_verification_code_163yidun(browser, cut_element, back_element,
                                      slider_element):
    while True:
        # 将验证码的背景图和滑块图片下载下来
        download_img_by_src(browser, back_element, 'back.jpg')
        download_img_by_src(browser, cut_element, 'cut.png')
        sleep(1)
        cut_image, back_image = read_img_file('cut.png', 'back.jpg')
        distance = get_distance(back_img=back_image, cut_img=cut_image)
        print(distance)
        if distance:
            action = ActionChains(browser)
            action.click_and_hold(
                browser.find_element(slider_element[0],
                                     slider_element[1])).perform()
            # tracks = get_track(distance)
            # for i in tracks:
            action.move_by_offset(xoffset=distance, yoffset=-1).perform()
            action = ActionChains(browser)
            sleep(1)
            action.release().perform()
            sleep(5)
        if re.findall("订单", browser.page_source, re.S):
            break
        if '失败过多,点此重试' in browser.page_source:
            browser.find_element_by_xpath(
                "//span[@class='yidun_tips__text']").click()
예제 #9
0
def login():
    options = Options()
    # 不能隐藏浏览器,会被检测到,要求登入账号
    # options.add_argument('--headless')
    # options.add_argument('--disable-gpu')
    # options.add_argument(
    #     '--user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"')
    # driver = selenium.webdriver.Chrome(options=options)
    # 等待时间
    # driver.implicitly_wait(5)
    # driver.delete_all_cookies()

    # 实例化driver
    driver = webdriver.Chrome()
    # driver = webdriver.Firefox()
    # driver.maximize_window()
    time.sleep(3)
    driver.get('https://www.qcc.com')
    time.sleep(3)
    try:
        # 页面一直循环,直到 id="myDynamicElement" 出现
        print(1)
        element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, "myDynamicElement")))
    finally:

        # 去除介绍界面,进入登录界面
        driver.find_element_by_class_name("tep1").click()
        time.sleep(3)
        # driver.find_element_by_xpath('//div[@class="login-panel-head clearfix"]/div[2]').click()

        # 选择密码登录模式
        driver.find_element_by_id("normalLogin").click()
        time.sleep(5)

        # 输入帐号密码
        driver.find_element_by_id("nameNormal").send_keys("13536020881")
        time.sleep(3)
        driver.find_element_by_id("pwdNormal").send_keys("123456789")
        time.sleep(3)

        # 滑动条定位
        start = driver.find_element_by_xpath(
            '//div[@id="nc_2__scale_text"]/span')
        # 长按拖拽
        action = ActionChains(driver)
        # 长按
        action.click_and_hold(start)
        # 拉动
        action.drag_and_drop_by_offset(start, 308, 0).perform()
        time.sleep(3)

        # 登录
        driver.find_element_by_xpath(
            '//form[@id="user_login_normal"]/button').click()
        time.sleep(2)

        # 获取cookies
        cookies = {i["name"]: i["value"] for i in driver.get_cookies()}
        print(cookies)
예제 #10
0
    def move_slider(self, gap):
        print("开始滑动")
        slider = self.wait.until(
            EC.presence_of_element_located((By.ID, 'test')))
        while 1:
            action = ActionChains(self.driver)
            action.click_and_hold(slider).perform()
            action.reset_actions()  # 清除之前的action
            track = self.get_move_track(gap)
            for x in track:  # 只有水平方向有运动 按轨迹移动
                ActionChains(self.driver).move_by_offset(xoffset=x,
                                                         yoffset=0).perform()
                sleep(0.2)
            sleep(1)
            ActionChains(self.driver).release().perform()  # 松开鼠标
            sleep(5)

            try:
                alert = self.driver.find_element_by_id('test')
            except Exception as e:
                print('get alert error: %s' % e)
                alert = ''
            if alert:
                print(u'滑块位移需要调整: %d' % gap)
                if gap > 240:
                    gap = 145
                gap += 15
                sleep(5)
            else:
                print('滑块验证通过')
                break
예제 #11
0
 def half_rotate(self):
     ac = ActionChains(self.driver)
     ac.move_to_element(self.tourImage())
     ac.click_and_hold()
     ac.move_by_offset(self.tourImage().size["width"] / 2, 0)
     ac.release()
     ac.perform()
예제 #12
0
    def test1(self):
        baseUrl = "https://jqueryui.com/droppable/"
        # driver = webdriver.Firefox()
        # driver.maximize_window()
        # driver.get(baseUrl)
        driverLocation = "/Users/harisrizwan/Selenium/chrome/chromedriver"
        os.environ["chrome.driver"] = driverLocation
        driver = webdriver.Chrome(driverLocation)
        driver.implicitly_wait(5)
        driver.maximize_window()
        driver.get(baseUrl)

        driver.switch_to.frame(0)

        #first method

        #Xpath not working to find the elemnt

        fromElement = driver.find_element(By.ID, "draggable")
        toElement = driver.find_element(By.ID, "droppable")

        actions = ActionChains(driver)
        # actions.drag_and_drop(fromElement,toElement).perform()

        #Second method

        actions.click_and_hold(fromElement).move_to_element(
            toElement).release().perform()

        time.sleep(7)
예제 #13
0
    def put_element_on_grid(self, type_str):
        '''find 'type_str' in the Library, drag and drop it onto the grid'''
        browser = self.browser

        grid = browser.find_element_by_xpath('//div[@id="-dataflow"]')

        for retry in range(3):
            try:
                objtype = self.find_library_button(type_str)
                chain = ActionChains(browser)
                chain.click_and_hold(objtype)
                chain.move_to_element_with_offset(grid, 10, 10).perform()
            except StaleElementReferenceException:
                if retry < 2:
                    logging.warning('put_element_on_grid %s:'
                                    ' StaleElementReferenceException', type_str)
                else:
                    raise
            else:
                break

        self.check_highlighting(grid, True, "Grid")
        self.release(chain)

        # deal with the modal dialog
        name = NameInstanceDialog(self).create_and_dismiss()

        # make sure it is on the grid
        self.ensure_names_in_workspace([name],
            "Dragging '" + type_str +
            "' to grid did not produce a new element on page")

        return name
def drag_scroll_by_css(browser, offset_x, offset_y):
    scroll, height = wait_element_present(browser)
    action = ActionChains(browser)
    try:
        action.click_and_hold(scroll[0]).move_by_offset(int(offset_x), int(offset_y) + 1).release().perform()
    except AssertionError:
        drag_scroll_by_css(browser, offset_x, offset_y)
예제 #15
0
    def _test_reorder_file_bar(self, page):
        page.add_file([x for x in FILES if x.name == 'test.jpg'][0])

        WebDriverWait(page.driver, 3).until(
            ec.visibility_of_element_located(
                (
                    By.CSS_SELECTOR,
                    'div.grid-canvas div.ui-widget-content.slick-row.odd'
                )
            )
        )

        ac = ActionChains(page.driver)
        a = page.driver.find_elements_by_css_selector(
            'DIV.container DIV.slick-header.ui-state-default DIV.slick-header-columns.ui-sortable SPAN.slick-column-name'
        )[3]
        b = page.driver.find_elements_by_css_selector(
            'DIV.container DIV.slick-header.ui-state-default DIV.slick-header-columns.ui-sortable SPAN.slick-column-name'
        )[0]

        ac.click_and_hold(a).perform()
        a_chain = ActionChains(page.driver)
        a_chain.move_to_element(b).perform()
        a_chain.release(b).perform()

        downloads = page.driver.find_element_by_css_selector(
            'div.grid-canvas div.ui-widget-content.slick-row.odd DIV.slick-cell.l0.r0'
        ).text

        self.assertIn('0', downloads)

        page.close()
예제 #16
0
def setup_google_driver():
	driver = webdriver.Firefox()
	driver.get('http://google.com')
	time.sleep(0.2)
	#driver.maximize_window()
	time.sleep(3)
	driver.get('http://google.com/preferences')
	time.sleep(2)
	radios = driver.find_elements_by_css_selector('div.jfk-radiobutton')
	radio = radios[-1]
	radio.click()
	time.sleep(1.2)
	slider = driver.find_element_by_css_selector('div.goog-slider-scale')
	dims = slider.size
	width = dims['width']
	move = ActionChains(driver)
	slider2 = driver.find_element_by_css_selector('div.goog-slider-scale')
	for i in range(4):
		time.sleep(0.1)
		move.click_and_hold(slider2).move_by_offset(width//9,0).release().perform()
	move.click_and_hold(slider2).move_by_offset(width//2,0).release().perform()
	time.sleep(1.5)
	driver.switch_to_default_content()
	#save settings
	elems = driver.find_elements_by_id('form-buttons')
	elems[0].find_elements_by_tag_name('div')[0].click()
	alert = driver.switch_to_alert()
	time.sleep(0.91)
	alert.accept()
	time.sleep(1)
	return driver
예제 #17
0
async def setup_challenge(driver, duration, no_move):
    # Click on the play button
    try:
        Utils.get_element(driver, xpath_play, 1).click()
    except Exception as _:
        time.sleep(1)
        Utils.get_element(driver, xpath_play_bis, 1).click()

    # Click on the challenge button
    Utils.get_element(driver, xpath_challenge).click()

    # Have settings been clicked already?
    try:
        driver.find_element(By.XPATH, xpath_no_move)
    except Exception as _:
        # Click settings 
        Utils.get_element(driver, xpath_settings).click()

    # No move
    if no_move:
        Utils.get_element(driver, xpath_no_move).click()

    else:
        Utils.get_element(driver, xpath_move).click()

    # Slide to the correct duration
    slider = Utils.get_element(driver, xpath_time)
    move = ActionChains(driver)
    move.click_and_hold(slider).move_by_offset(-100, 0).release().perform()
    move.click_and_hold(slider).move_by_offset(int(duration / 10) * shift, 0).release().perform()

    # Get to the URL of the challenge
    Utils.get_element(driver, xpath_inviteFriends).click()
예제 #18
0
    def view_tour(self, where, number):
        number = number * 2
        for i in range(number):
            time.sleep(2)
            moveForX = int(int(self.tourImage().size["width"]) / 8)
            moveForY = int(int(self.tourImage().size["height"]) / 8)
            ac = ActionChains(self.driver)
            if not self._check_hotSpot_on_view():
                ac.move_to_element(self.tourImage())
            else:
                if i == 0:
                    ac.move_to_element(self.tourImage())
                    hs_loc = self.where_to_move_edit_and_view()
                    if where == "right":
                        ac.move_by_offset(-1 * hs_loc[0], 0)
                    elif where == "left":
                        ac.move_by_offset(hs_loc[1], 0)
                else:
                    break
            ac.click_and_hold()

            if where == "right":
                ac.move_by_offset(moveForX * -1, 0)
            elif where == "left":
                ac.move_by_offset(moveForX, 0)
            elif where == "up":
                ac.move_by_offset(0, moveForY * -1)
            elif where == "down":
                ac.move_by_offset(0, moveForY)
            ac.release()
            try:
                ac.perform()
            except:
                pass
            time.sleep(2)
예제 #19
0
def drag_horizontal_offset(browser, offsetx):
    horizontal_css = ".antiscroll-scrollbar.antiscroll-scrollbar-horizontal"
    elements = browser.find_elements_by_css_selector(horizontal_css)

    action = ActionChains(browser)
    action.click_and_hold(elements[0]).move_by_offset(int(offsetx),
                                                      0).release().perform()
예제 #20
0
 def open_url(self, url):
     options = webdriver.ChromeOptions()
     # 不加载图片,加快访问速度
     # options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
     # 此步骤很重要,设置为开发者模式,防止被各大网站识别出来使用了Selenium
     options.add_experimental_option('excludeSwitches',
                                     ['enable-automation'])
     options.add_argument('--headless')
     browser = webdriver.Chrome(
         executable_path="G:\chromedriver_win32\chromedriver.exe",
         options=options)
     wait = WebDriverWait(browser, 10)  # 超时时长为10s
     # 打开网页
     browser.get(url)
     try:
         WebDriverWait(browser, 5, 0.5).until(
             EC.presence_of_element_located(
                 (By.ID, "nc_1__scale_text")))  # 等待滑动拖动控件出现
         swipe_button = browser.find_element_by_xpath(
             '//*[@id="nc_1__scale_text"]/span')  # 获取滑动拖动控件
         # 模拟拽托
         action = ActionChains(browser)  # 实例化一个action对象
         action.click_and_hold(
             swipe_button).perform()  # perform()用来执行ActionChains中存储的行为
         action.reset_actions()
         action.move_by_offset(580, 0).perform()  # 移动滑块
     except Exception as e:
         print('get button failed: ', e)
예제 #21
0
 def enter_ZipCode(self):
     myAction = ActionChains(self.driver)
     textBox_ZipCode = self.driver.find_element_by_id(self.ID_ZipCode)
     myAction.click_and_hold(textBox_ZipCode)
     myAction.send_keys_to_element(textBox_ZipCode, "16030")
     myAction.perform()
     time.sleep(0.5)
예제 #22
0
    def test_drag_drop(self):
        self.driver.get("http://sahitest.com/demo/dragDropMooTools.htm")
        element_drag = self.driver.find_element_by_xpath('//*[@id="dragger"]')
        element_drop_item1 = self.driver.find_element_by_xpath(
            '/html/body/div[2]')
        element_drop_item2 = self.driver.find_element_by_xpath(
            '/html/body/div[3]')
        element_drop_item3 = self.driver.find_element_by_xpath(
            '/html/body/div[4]')
        element_drop_item4 = self.driver.find_element_by_xpath(
            '/html/body/div[5]')
        action = ActionChains(self.driver)

        # ActionChains(self.driver).drag_and_drop(element_drag_drop,element_drag_drop_item1).perform()
        # sleep(2)
        # ActionChains(self.driver).drag_and_drop(element_drag_drop,element_drag_drop_item2).perform()
        # sleep(2)
        # ActionChains(self.driver).drag_and_drop(element_drag_drop,element_drag_drop_item3).perform()
        # sleep(2)
        # ActionChains(self.driver).drag_and_drop(element_drag_drop,element_drag_drop_item4).perform()
        # sleep(2)

        # 释放对象释放错了,谨记谨记谨记!!!!
        action.drag_and_drop(element_drag,
                             element_drop_item1).release().pause(1)
        action.click_and_hold(element_drag).move_to_element(
            element_drop_item2).release().pause(1)
        action.drag_and_drop(element_drag,
                             element_drop_item3).release().pause(1)
        action.click_and_hold(element_drag).move_to_element(
            element_drop_item4).release().pause(1)
        action.perform()
        sleep(5)
        self.driver.quit()
 def test_history(self):
     '''
     1. Get the outer div id of the activecode component
     2. Find the run button using its class name
     3. Run the example
     4. Check the output from the ac_output element
     :return:
     '''
     self.driver.get(self.host + "/index.html")
     t1 = self.driver.find_element_by_id("test1")
     self.assertIsNotNone(t1)
     rb = t1.find_element_by_class_name("run-button")
     self.assertIsNotNone(rb)
     rb.click()
     ta = t1.find_element_by_class_name("cm-s-default")
     self.assertIsNotNone(ta)
     self.driver.execute_script("""edList['test1'].editor.setValue("print('GoodBye')")""")
     WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "run-button")))
     rb.click()
     output = t1.find_element_by_class_name("ac_output")
     self.assertEqual(output.text.strip(),"GoodBye")
     move = ActionChains(self.driver)
     slider = t1.find_element_by_class_name("ui-slider")
     width = slider.size['width']
     slider = t1.find_element_by_class_name("ui-slider-handle")
     move.click_and_hold(slider).move_by_offset(-width,0).release().perform()
     rb.click()
     output = t1.find_element_by_class_name("ac_output")
     self.assertEqual(output.text.strip(), "Hello World")
예제 #24
0
    def test(self):
        driver = webdriver.Chrome(
            executable_path="/usr/local/bin/chromedriver")
        driver.maximize_window()
        driver.implicitly_wait(10)
        driver.get("https://jqueryui.com/droppable/")

        iframe = driver.find_element(By.XPATH, "//iframe[@class='demo-frame']")
        driver.switch_to.frame(iframe)
        print("Switched to frame..")
        src_ele = driver.find_element(By.XPATH, "//div[@id='draggable']")
        dest_ele = driver.find_element(By.XPATH, "//div[@id='droppable']")
        try:
            action = ActionChains(driver)
            # Method 1(easy method)
            # action.drag_and_drop(src_ele, dest_ele).perform()

            # method -2 (chaining and performing)
            action.click_and_hold(src_ele).pause(3).move_to_element(
                dest_ele).release().perform()
            print("drag and drag executed..")
            time.sleep(5)
        except:
            print("Something went wrong in actionsclasss")

        time.sleep(10)
        driver.quit()
예제 #25
0
def dealCheck(browser):
    js1 = '''Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) '''
    js2 = '''window.navigator.chrome = { runtime: {},  }; '''
    js3 = '''Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] }); '''
    js4 = '''Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); '''
    browser.execute_script(js1)
    browser.execute_script(js2)
    browser.execute_script(js3)
    browser.execute_script(js4)
    time.sleep(1)
    while True:
        buttons = browser.find_elements_by_id('nc_1_n1z')
        if len(buttons) > 0:
            print("no!")
            action = ActionChains(browser)
            action.click_and_hold(buttons[0]).perform()
            action.reset_actions()
            action.move_by_offset(320, 0).perform()
            time.sleep(3)
            js1 = '''Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) '''
            js2 = '''window.navigator.chrome = { runtime: {},  }; '''
            js3 = '''Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] }); '''
            js4 = '''Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); '''
            browser.execute_script(js1)
            browser.execute_script(js2)
            browser.execute_script(js3)
            browser.execute_script(js4)
        else:
            break
예제 #26
0
 def denglu(self, uname, pword):
     #try:
     # 定位到iframe
     iframe = browser.find_element_by_id("alibaba-login-box")
     # 切换到iframe
     browser.switch_to.frame(iframe)
     # 输入账号密码,点击登录按钮
     browser.find_element_by_id("fm-login-id").send_keys(uname)
     browser.find_element_by_id("fm-login-password").send_keys(pword)
     browser.find_element_by_id("fm-login-submit").click()
     time.sleep(3)
     # 滑动验证码
     action = ActionChains(browser)
     source = browser.find_element_by_xpath(
         "//*[@id='nc_1_n1t']/span")  # 需要滑动的元素
     action.click_and_hold(source).perform()  # 鼠标左键按下不放
     # 这里每次移动的位置都一样的话,会被反爬虫机制限制滑不到最后
     action.move_by_offset(33, 0).perform()  # 需要滑动的坐标
     time.sleep(0.1)
     action.move_by_offset(43, 0).perform()
     time.sleep(0.3)
     action.move_by_offset(53, 0).perform()
     time.sleep(0.1)
     action.move_by_offset(103, 0).perform()
     time.sleep(0.2)
     #action.release().perform()  # 释放鼠标
     self.getloginbutton().click()  #滑到最后还要再点一次登录
     time.sleep(5)
예제 #27
0
    def move2(self, browser):
        """
        complete actions of sliding captcha
        """
        self.save_img(browser)
        self.calc_position(browser)

        offset = self.get_offset('./captcha/template1.jpg',
                                 './captcha/template2.jpg')
        print("offset calc by get_offset() is: {}".format(offset))
        tracks = self.get_tracks(offset)
        print("the track array is: {}".format(tracks))

        slider = browser.find_element_by_class_name("JDJRV-slide-btn")
        action = ActionChains(browser)
        action.click_and_hold(slider).perform()
        action.reset_actions()

        for i in tracks:
            action.move_by_offset(round(i), 0).perform()
            print('should move--<{}>--'.format(i))
            print('moving--<{}>--'.format(slider.location['x']))
            time.sleep(0.1)
            # in order to prevent accumulation actions
            action.reset_actions()  # useful
            # action = ActionChains(browser)   # useful

        time.sleep(4)
        action.release().perform()
예제 #28
0
 def create_campaign(self, campaign_name=None):
     if campaign_name is None:
         campaign_name = f"Campaign {randint(1, 100)}{randint(1, 100)}"
     self.click(self.locators.TRAFFIC_BUTTON)
     link_field = self.find(self.locators.LINK_FIELD)
     link_field.clear()
     link_field.send_keys(LINK)
     campaign_name_field = self.find(self.locators.CAMPAIGN_NAME_FIELD)
     self.click(self.locators.CAMPAIGN_NAME_FIELD_CLEAR_BUTTON)
     campaign_name_field.send_keys(campaign_name)
     self.click(self.locators.BANNER_BUTTON)
     self.click(self.locators.PIN_BUTTON)
     # Попытка 1
     image_from_library = self.find(self.locators.IMAGE_FROM_LIBRARY)
     image_preview = self.find(self.locators.IMAGE_PREVIEW)
     ac = ActionChains(self.driver)
     ac.drag_and_drop(image_from_library, image_preview).perform()
     # Попытка 2
     ac.click_and_hold(image_from_library).move_to_element(
         image_preview).release().perform()
     # Попытка 3
     file_input = self.find(self.locators.FILE_INPUT)
     filepath = os.path.abspath("63C08B.jpg")
     file_input.send_keys(filepath)
     self.click(self.locators.CREATE_CAMPAIGN_LAST_BUTTON)
     return campaign_name
예제 #29
0
    def add_library_item_to_dataflow(self, item_name, instance_name, check=True, offset=None, prefix=None):
        """ Add component `item_name`, with name `instance_name`. """
        library_item = self.get_library_item(item_name)

        target = WebDriverWait(self.browser, TMO).until(
            lambda browser: browser.find_element_by_xpath("//*[@id='-dataflow']")
        )

        offset = offset or (90, 90)
        chain = ActionChains(self.browser)
        if False:
            chain.drag_and_drop(library_item, target)
        else:
            chain.click_and_hold(library_item)
            chain.move_to_element_with_offset(target, offset[0], offset[1])
            chain.release(None)
        chain.perform()

        page = ValuePrompt(self.browser, self.port)
        page.set_value(instance_name)
        # Check that the prompt is gone so we can distinguish a prompt problem
        # from a dataflow update problem.
        time.sleep(0.25)
        self.browser.implicitly_wait(1)  # We don't expect to find anything.
        try:
            eq(len(self.browser.find_elements(*page("prompt")._locator)), 0)
        finally:
            self.browser.implicitly_wait(TMO)

        retval = None
        if check:  # Check that it's been added.
            retval = WebDriverWait(self.browser, TMO).until(
                lambda browser: self.get_dataflow_figure(instance_name, prefix)
            )
        return retval
예제 #30
0
 def add_extra_item(self, driver):
     gps = self.driver.find_element_by_xpath(self.GPS_item_xpath)
     baby_seat = self.driver.find_element_by_xpath(self.Baby_seat_xpath)
     move = ActionChains(driver)
     move.click_and_hold(gps).move_by_offset(10, 0).release().perform()
     move.click_and_hold(baby_seat).move_by_offset(10,
                                                   0).release().perform()
예제 #31
0
 def test_findElement(self):
     time.sleep(5)
     fromElement = self.driver.find_element(By.ID, "draggable")
     toElement = self.driver.find_element(By.ID, "droppable")
     actions = ActionChains(self.driver)
     actions.click_and_hold(fromElement).move_to_element(toElement).release().perform()
     time.sleep(5)
예제 #32
0
    def test1(self):
        driver = None
        try:
            baseUrl = "https://jqueryui.com/droppable/"
            driver = webdriver.Firefox()
            driver.maximize_window()
            driver.get(baseUrl)
            driver.implicitly_wait(3)

            driver.switch_to.frame(0)

            fromElement = driver.find_element(By.ID, "draggable")
            toElement = driver.find_element(By.ID, "droppable")
            time.sleep(2)
            try:
                actions = ActionChains(driver)
                #actions.drag_and_drop(fromElement, toElement).perform()
                actions.click_and_hold(fromElement).move_to_element(
                    toElement).release().perform()
                print("Drag And Drop Element Successful")
                time.sleep(2)
            except:
                print("Drag And Drop failed on element")
        except:
            print("Inside Error")
        finally:
            driver.quit()
예제 #33
0
def activatePropertyBoundary():
    # Function navigates MapBrowser to activate cadastre boundary area and decreases transparency
    # Only has to be run once per session
    locateAndClickButton(By.XPATH, '/html/body/div[2]/div[19]', 0)
    locateAndClickButton(
        By.XPATH,
        '/html/body/div[4]/div[4]/div/div[3]/div/div[4]/div/div[2]/ul/li[1]/div',
        0)  # Clicks the Boundaries button
    # Property boundary button
    # locateAndClickButton(By.XPATH, '/html/body/div[4]/div[4]/div/div[3]/div/div[4]/div/div[2]/ul/li[1]/ul/li[7]/label', 0)
    # Cadastre boundary button
    locateAndClickButton(
        By.XPATH,
        '/html/body/div[4]/div[4]/div/div[3]/div/div[4]/div/div[2]/ul/li[1]/ul/li[1]/label',
        0)
    sliderbutton = WebDriverWait(browser, 30).until(
        EC.presence_of_element_located((
            By.XPATH,
            '/html/body/div[4]/div[4]/div/div[3]/div/div[4]/ul/li/div[3]/span/div/div/div'
        )))  # Sets transparency slide to opaque
    actionControl = ActionChains(browser)
    actionControl.click_and_hold(sliderbutton).move_by_offset(
        200, 0).release().perform()
    # Closes layer popup
    locateAndClickButton(By.XPATH, '/html/body/div[4]/div[4]/div/div[2]')
예제 #34
0
 def test_TC_Promotion_Mission_02_Cancel_Member_Promotion(self):
     Promotion_Mission_Actions.Navigate_Promotion_Mission(self)
     # Scroll page to the bottom
     scroll_to_bottom = self.driver.find_element_by_class_name(
         Promotion_Mission_Element.scroll_to_bottom)
     actions = ActionChains(self.driver)
     actions.move_to_element(scroll_to_bottom)
     actions.perform()
     # Move the slidebar
     slide_bar = self.driver.find_element_by_class_name(
         Promotion_Mission_Element.slide_bar)
     move = ActionChains(self.driver)
     move.click_and_hold(slide_bar).move_by_offset(300,
                                                   0).release().perform()
     self.driver.implicitly_wait(30)
     # Wait till button is clickable
     wait_cancel_button = EC.element_to_be_clickable(
         (By.CLASS_NAME, Promotion_Mission_Element.cancel_promotion_button))
     WebDriverWait(self.driver, 10).until(wait_cancel_button)
     print("<li>" + "Click on Delete button" + "</li>" + "<br>")
     self.driver.find_element_by_class_name(
         Promotion_Mission_Element.cancel_promotion_button).click()
     # Assert Change dialog is displayed
     wait_lock_change_dialog_box = EC.presence_of_element_located(
         (By.XPATH, Promotion_Mission_Element.lock_change_submit_button))
     WebDriverWait(self.driver, 10).until(wait_lock_change_dialog_box)
     lock_change_dialog_box = self.driver.find_element_by_xpath(
         Promotion_Mission_Element.lock_change_submit_button).is_displayed(
         )
     self.assertTrue(
         lock_change_dialog_box,
         "User is not able to access to cancel Member Promotion.")
     print("Expected Results: Cancel dialog box popped out." + "<br>")
예제 #35
0
    def _add_button_to_center_firefox(self, hotSpot):
        """
        Puts hotSpot or info in center of scene.

        :param hotSpot: True if hotSpot is added, False if info is added
        :type hotSpot: bool
        """
        self.log.info("Execute method _add_button_to_center")
        if hotSpot:
            button = self.btnHotSpot
        else:
            button = self.btnInfo
        scroll_element_to_center(self.driver, self.log, button())
        buttonSize = button().size
        ac = ActionChains(self.driver)
        time.sleep(3)
        ac.move_to_element_with_offset(button(), buttonSize["width"] / 2,
                                       buttonSize["height"] / 2).perform()
        time.sleep(3)
        ac.click_and_hold().perform()
        tourSize = self.tourImage().size
        time.sleep(3)
        #scroll_element_to_viewPoint_with_selenium(self.driver, self.tourImage())
        scroll_element_to_viewpoint_top(self.log, self.driver,
                                        self.tourImage())
        time.sleep(1)
        move_mouse_to_middle_of_browser(self.log, self.driver)
        time.sleep(1)
        ac.move_to_element_with_offset(self.tourImage(), tourSize["width"] / 2,
                                       tourSize["height"] / 2).perform()
        ac.release().perform()
        time.sleep(1)
        self.log.screenshot("Button is added")
예제 #36
0
def slide_discern():
    print("滑块验证码验证中。。。")
    # try:
    # 获取到需滑动的按钮
    source = driver.find_element_by_xpath('//*[@id="nc_1_n1z"]')
    action = ActionChains(driver)
    # 按住左键不放
    action.click_and_hold(source).perform()
    # 开始滑动
    distance = 348  # 模拟以人为速度拖动
    track = get_track(distance)
    # ttt = [23, 81, 224]
    for i in track:
        try:
            action.move_by_offset(xoffset=i, yoffset=0).perform()   # perform --- 执行所有准备好的Action
            # action.reset_actions()  # reset_actions --- 清空所有准备好的Action,这个需要selenium版本3.0以上
            # time.sleep(0.4)
        except StaleElementReferenceException as e:
            action.release().perform()  # 释放鼠标
            driver.find_element_by_xpath('//div[@class="errloading"]/span/a').click()
            source = driver.find_element_by_xpath('//*[@id="nc_1_n1z"]')    # 获取到需滑动的按钮
            action = ActionChains(driver)
            action.click_and_hold(source).perform() # 按住左键不放
            # action.reset_actions()  # 清除之前的action
            action.move_by_offset(xoffset=i, yoffset=0).perform()  # perform --- 执行所有准备好的Action
    # 释放鼠标
    action.release().perform()
def reorder_column_by_index(browser, index, left_or_right, offsetx):
    chains = ActionChains(browser)
    wait_for_elem(browser, "return $('.ember-table-content-container')")
    element = browser.execute_script(
        "return $('.ember-table-content-container .ember-table-content:eq(" + str(index) + ")')")
    if left_or_right == "left":
        chains.click_and_hold(element[0]).move_by_offset(-int(offsetx), 0).release().perform()
    else:
        chains.click_and_hold(element[0]).move_by_offset(int(offsetx), 0).release().perform()
def reorder_column_with_offset(browser, css, index, rightOrLeft, offset):
    columnsHeader = find_elements_by_css(browser, css)
    action_chains = ActionChains(browser)
    if str(rightOrLeft) == "left":
        action_chains.click_and_hold(columnsHeader[int(index) - 1]).move_by_offset(-int(offset), 0).move_by_offset(10,
                                                                                                                   0).release().perform()
    else:
        action_chains.click_and_hold(columnsHeader[int(index) - 1]).move_by_offset(int(offset), 0).move_by_offset(-10,
                                                                                                                  0).release().perform()
예제 #39
0
파일: map.py 프로젝트: 2gis/mapsapi
 def zoom_selection(self):
     center = self.driver.execute_script(GetScripts.getContainerCenter)
     actions = ActionChains(self.driver)
     actions.move_to_element_with_offset(self.element, int(center['x']), int(center['y']))
     actions.key_down(Keys.SHIFT)
     actions.click_and_hold()
     actions.move_by_offset(300, 300)
     actions.release()
     actions.perform()
예제 #40
0
def drag_hold_column(step, column_name, left_or_right, offsetx):
    with AssertContextManager(step):
        chains = ActionChains(world.browser)
        wait_for_elem(world.browser, "return $('.ember-table-content-container')")
        element = world.browser.execute_script(
            "return $('.ember-table-content-container .ember-table-content:contains(" + column_name + ")')")
        if left_or_right == "left":
            chains.click_and_hold(element[0]).move_by_offset(-int(offsetx), 0).perform()
        else:
            chains.click_and_hold(element[0]).move_by_offset(int(offsetx), 0).perform()
예제 #41
0
    def add_library_item_to_dataflow(self, item_name, instance_name,
                                     check=True, offset=None, prefix=None,
                                     args=None):
        """ Add component `item_name`, with name `instance_name`. """
        offset = offset or (90, 90)
        xpath = "//*[@id='-dataflow']"
        library_item = self.get_library_item(item_name)
        target = WebDriverWait(self.browser, TMO).until(
                           lambda browser: browser.find_element_by_xpath(xpath))

        for retry in range(3):
            try:
                chain = ActionChains(self.browser)
                if False:
                    chain.drag_and_drop(library_item, target)
                else:
                    chain.click_and_hold(library_item)
                    chain.move_to_element_with_offset(target,
                                                      offset[0], offset[1])
                    chain.release(None)
                chain.perform()
            except StaleElementReferenceException:
                if retry < 2:
                    logging.warning('add_library_item_to_dataflow:'
                                    ' StaleElementReferenceException')
                    library_item = self.get_library_item(item_name)
                    target = WebDriverWait(self.browser, TMO).until(
                           lambda browser: browser.find_element_by_xpath(xpath))
                else:
                    raise
            else:
                break

        page = ArgsPrompt(self.browser, self.port)
        page.set_name(instance_name)
        if args is not None:
            for i, arg in enumerate(args):
                page.set_argument(i, arg)
            page.click_ok()

        # Check that the prompt is gone so we can distinguish a prompt problem
        # from a dataflow update problem.
        time.sleep(0.25)
        self.browser.implicitly_wait(1)  # We don't expect to find anything.
        try:
            eq(len(self.browser.find_elements(*page('prompt')._locator)), 0)
        finally:
            self.browser.implicitly_wait(TMO)

        retval = None
        if check:  # Check that it's been added.
            retval = WebDriverWait(self.browser, TMO).until(
                        lambda browser: self.get_dataflow_figure(instance_name,
                                                                 prefix))
        return retval
예제 #42
0
 def drag_element_to(self, element, drag_to, center):
     '''Drag one element over to another element'''
     chain = ActionChains(self.browser)
     chain.move_to_element(element)
     chain.click_and_hold(element)
     if center:
         # move to center of element
         chain.move_to_element(drag_to)
     else:
         # move to offset from top left of element
         chain.move_to_element_with_offset(drag_to, 2, 2)
     chain.perform()
     return chain
예제 #43
0
def action_elements_events(self, element_menu, drag_divs):
    action = ActionChains(self.driver)
    action.move_to_element(element_menu).click(element_menu)
    action.click_and_hold(drag_divs)
    action.move_by_offset(35, 35)
    action.move_by_offset(15, 20)
    action.move_by_offset(55, 15)
    action.release()
    action.perform()
    event_start = self.driver.find_element_by_xpath("//li[@id = 'event-start']/span[2]").text
    event_drag = self.driver.find_element_by_xpath("//li[@id='event-drag']/span[2]").text
    event_stop = self.driver.find_element_by_xpath("//li[@id = 'event-stop']/span[2]").text
    return event_start, event_drag, event_stop
예제 #44
0
 def connect(self, src, dst):
     """ Return :class:`ConnectionsPage` for connecting `src` to `dst`. """
     chain = ActionChains(self.browser)
     chain.click_and_hold(src.output_port)
     # Using root rather than input_port since for some reason
     # even using a negative Y offset can select the parent's input.
     chain.move_to_element(dst.input_port)
     chain.release(None)
     chain.perform()
     parent, dot, srcname = src.pathname.rpartition(".")
     parent, dot, dstname = dst.pathname.rpartition(".")
     editor_id = "ConnectionsFrame-%s" % (parent)
     editor_id = editor_id.replace(".", "-")
     return ConnectionsPage(self.browser, self.port, (By.ID, editor_id))
예제 #45
0
    def replace(self, name, classname, confirm=True):
        """ Replace `name` with an instance of `classname`. """
        library_item = self.get_library_item(classname)
        target = self.get_dataflow_figure(name).root

        chain = ActionChains(self.browser)
        chain.click_and_hold(library_item)
        chain.move_to_element_with_offset(target, 125, 30)
        chain.release(None)
        chain.perform()

        dialog = ConfirmationPage(self)
        if confirm:
            dialog.click_ok()
        else:
            dialog.click_cancel()
예제 #46
0
 def add_object_to_workflow(self, obj_path, target_name):
     """ Add `obj_path` object to `target_name` in workflow. """
     for retry in range(3):
         try:
             obj = self.find_object_button(obj_path)
             target = self.get_workflow_figure(target_name)
             chain = ActionChains(self.browser)
             chain.move_to_element(obj)
             chain.click_and_hold(obj)
             chain.move_to_element(target.root)
             chain.move_by_offset(2, 1)
             chain.release(None)
             chain.perform()
         except StaleElementReferenceException:
             if retry < 2:
                 logging.warning("add_object_to_workflow:" " StaleElementReferenceException")
             else:
                 raise
         else:
             break
예제 #47
0
 def choose_age(self, left_offset, right_offset):
     el = WebDriverWait(self.driver, 30, 0.5).until(
         lambda d: d.find_element_by_css_selector(CreateEl.AGE_GROUP)
     )
     age_el = WebDriverWait(el, 30, 0.5).until(
         lambda e: e.find_element_by_css_selector(CreateEl.AGE)
     )
     age_el.click()
     if left_offset > 0:
         left = WebDriverWait(self.driver, 30, 0.1).until(
             lambda d: d.find_element_by_css_selector(CreateEl.LEFT_SLIDER)
         )
         ac = ActionChains(self.driver)
         ac.click_and_hold(left).move_by_offset(left_offset, 0).release().perform()
     if right_offset > 0:
         right = WebDriverWait(self.driver, 30, 0.1).until(
             lambda d: d.find_element_by_css_selector(CreateEl.RIGHT_SLIDER)
         )
         ac = ActionChains(self.driver)
         ac.click_and_hold(right).move_by_offset(-right_offset, 0).release().perform()
예제 #48
0
    def _add_device(self, port, device_type_id):
        browser = self._browser
        test_bed = browser.find_element_by_id('test-bed')
        device = browser.find_element_by_id(device_type_id)
        # drag
        action_chains = ActionChains(browser)
        action_chains.click_and_hold(device)
        action_chains.move_to_element(test_bed).perform()
        time.sleep(1)

        # drop
        drop_hw = browser.find_element_by_class_name('drop-hw')
        action_chains = ActionChains(browser)
        action_chains.move_to_element(drop_hw)
        action_chains.release(drop_hw).perform()

        time.sleep(0.5)
        selected_hw = browser.find_element_by_class_name('selected-hw')
        form_inputs = selected_hw.find_elements_by_tag_name('input')
        form_port = form_inputs[0]
        form_port.clear()
        form_port.send_keys(port)
예제 #49
0
    def test_assign_user_to_groups(self):
        driver = self.driver
        driver.get(self.base_url + "/ev/login")
        driver.find_element_by_id("form.password").clear()
        driver.find_element_by_id("form.password").send_keys("")
        driver.find_element_by_id("form.login").clear()
        driver.find_element_by_id("form.login").send_keys("andrew")
        driver.find_element_by_id("form.password").clear()
        driver.find_element_by_id("form.password").send_keys("andrew")
        driver.find_element_by_css_selector("span.commonButton.login_ok").click()
        gb_frame(self)

        driver.get(self.base_url + "/ev/setupusersorgroups")
        try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='users_user"+testUserIdValue+"']/div/div"))
        except AssertionError as e: self.verificationErrors.append(str(e))
        try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='userGroup_userGroup"+testUserGroupIdValue+"']"))
        except AssertionError as e: self.verificationErrors.append(str(e))
        element = driver.find_element_by_xpath("//li[@id='users_user"+testUserIdValue+"']/div/div")
        target = driver.find_element_by_xpath("//li[@id='userGroup_userGroup"+testUserGroupIdValue+"']")
        action_chains = ActionChains(driver)
        action_chains.click_and_hold(element)
        action_chains.move_to_element(target)
    def setUpClass(cls):
        super(ReorderComponentTest, cls).setUpClass()
        cls.project_url = cls.page.driver.current_url
        cls.page.add_component(
            title='first',
            component_type='hypothesis',
        )
        cls.page.driver.get(cls.project_url)
        cls.page.add_component(
            title='second',
            component_type='hypothesis',
        )
        cls.title = cls.page.title
        cls.page.driver.get(cls.project_url)

        # Second method: by element
        ac = ActionChains(cls.page.driver)
        a = cls.page.driver.find_element_by_css_selector('#Nodes li:first-child')
        b = cls.page.driver.find_element_by_css_selector('#Nodes li:last-child')
        ac.click_and_hold(a).perform()
        a_chain = ActionChains(cls.page.driver)
        a_chain.move_to_element(b).perform()
        a_chain.release(b).perform()
예제 #51
0
    def fill_slot_from_library(self, slot, classname, args=None):
        """ Fill slot with `classname` instance from library. """
        for retry in range(3):
            try:
                button = self.find_library_button(classname)
                chain = ActionChains(self.browser)
                chain.move_to_element(button)
                chain.click_and_hold(button)
                chain.move_to_element(slot.root)
                chain.release(None)
                chain.perform()
            except StaleElementReferenceException:
                if retry < 2:
                    logging.warning('fill_slot_from_library:'
                                    'StaleElementReferenceException')
                else:
                    raise
            else:
                break

        # Handle arguments for the slotted class
        page = ArgsPrompt(self.browser, self.port)
        argc = page.argument_count()
        if argc > 0:
            if args is not None:
                for i, arg in enumerate(args):
                    page.set_argument(i, arg)
            page.click_ok()

        # Check that the prompt is gone so we can distinguish a prompt problem
        # from a dataflow update problem.
        time.sleep(0.5)
        self.browser.implicitly_wait(1)  # We don't expect to find anything.
        try:
            eq(len(self.browser.find_elements(*page('prompt')._locator)), 0)
        finally:
            self.browser.implicitly_wait(TMO)
예제 #52
0
파일: _tester.py 프로젝트: 151706061/X
  def interact_mouse( self ):
    '''
    Perform some mouse interaction in the current active browser window.
    '''
    canvas = self.__browser.find_element_by_tag_name( 'canvas' )

    canvas_width = canvas.get_attribute('width')
    canvas_height = canvas.get_attribute('height')

    # move to canvas center to trigger a caption
    actions = ActionChains( self.__browser )
    actions.click( canvas )    
    actions.move_to_element_with_offset( canvas, int(canvas_width)/2, int(canvas_height)/2 )
    actions.perform()
    time.sleep(3)

    #
    # rotate, pan, zoom
    #
    
    actions = ActionChains( self.__browser )
    actions.click( canvas )

    # rotate
    for i in range( 30 ):
      actions.click_and_hold( None )
      actions.move_to_element_with_offset( canvas, 10, 0 );
      actions.release( canvas )
    for i in range( 30 ):
      actions.click_and_hold( None )
      actions.move_to_element_with_offset( canvas, 0, -10 );
      actions.release( canvas )

    # zoom (not possible right now since the scrollwheel can't be triggered)

    # pan
    for i in range( 10 ):
      actions.key_down( Keys.LEFT_SHIFT )
      actions.click_and_hold( None )
      actions.move_to_element_with_offset( canvas, 0, 10 );
      actions.release( canvas )

    actions.perform()
def drag_horizontal_offset(browser, offsetx):
    horizontal_css = ".antiscroll-scrollbar.antiscroll-scrollbar-horizontal"
    elements = browser.find_elements_by_css_selector(horizontal_css)

    action = ActionChains(browser)
    action.click_and_hold(elements[0]).move_by_offset(int(offsetx), 0).release().perform()
예제 #54
0
 def move(self, offset):
     element = WebDriverWait(self.driver, 30, 0.1).until(
         lambda d: d.find_element_by_css_selector(self.SLIDER)
     )
     ac = ActionChains(self.driver)
     ac.click_and_hold(element).move_by_offset(offset, 0).perform()
예제 #55
0
    def _test_bed(self):
        """Set up the test bed.

        Connect number of golden devices required by each case.
        """
        browser = self._browser
        test_bed = browser.find_element_by_id('test-bed')
        time.sleep(3)
        history = HistoryHelper()
        selected_hw_set = test_bed.find_elements_by_class_name('selected-hw')
        selected_hw_num = len(selected_hw_set)

        while selected_hw_num:
            remove_button = selected_hw_set[selected_hw_num - 1].find_element_by_class_name(
                'removeSelectedDevice')
            remove_button.click()
            selected_hw_num = selected_hw_num - 1

        devices = filter(lambda port: not history.is_bad_golden_device(port),
                         settings.GOLDEN_DEVICES)
        logger.info('Available golden devices: %s', json.dumps(devices, indent=2))
        if len(devices) < self.golden_devices_required:
            raise Exception('Golden devices is not enough')
        golden_devices_required = self.golden_devices_required
        while golden_devices_required:
            golden_device = browser.find_element_by_id(settings.GOLDEN_DEVICE_TYPE)
            # drag
            action_chains = ActionChains(browser)
            action_chains.click_and_hold(golden_device)
            action_chains.move_to_element(test_bed).perform()
            time.sleep(1)

            # drop
            drop_hw = browser.find_element_by_class_name('drop-hw')
            action_chains = ActionChains(browser)
            action_chains.move_to_element(drop_hw)
            action_chains.release(drop_hw).perform()

            time.sleep(0.5)
            golden_devices_required = golden_devices_required - 1

        selected_hw_set = test_bed.find_elements_by_class_name('selected-hw')
        for selected_hw in selected_hw_set:
            form_inputs = selected_hw.find_elements_by_tag_name('input')
            form_port = form_inputs[0]
            form_port.clear()
            device = devices.pop()
            form_port.send_keys(device)

        while True:
            try:
                self._connect_devices()
                elem = browser.find_element_by_id('nextBtn')
                if not self.wait_until(lambda: 'disabled' not in elem.get_attribute('class'),
                                       times=60):
                    for selected_hw in selected_hw_set:
                        form_inputs = selected_hw.find_elements_by_tag_name('input')
                        form_port = form_inputs[0]
                        if form_port.is_enabled():
                            port = form_port.get_attribute('value').encode('utf8')
                            history.mark_bad_golden_device(port)
                            if devices:
                                device = devices.pop()
                                form_port.clear()
                                form_port.send_keys(device)
                            else:
                                devices = None

                    if devices is None:
                        logger.warning('Golden devices not enough')
                        raise SystemExit()
                    else:
                        logger.info('Try again with new golden devices')
                        continue

                elem.click()
            except SystemExit:
                raise
            except:
                logger.exception('Unexpected error')
            else:
                break
예제 #56
0
파일: base.py 프로젝트: djay93/qtest
 def move_slider_by_pixel(self, element, pixel, parent = None):
     ele = self.find_element(element, parent)
     action_chains = ActionChains(self.get_driver())
     action_chains.click_and_hold(ele).move_by_offset(pixel, 0).release(ele).perform()
def drag_scroll_by_css(browser, css, offsetx, offsety):
    scroll = browser.find_element_by_css_selector(css)
    action = ActionChains(browser)
    action.click_and_hold(scroll).move_by_offset(int(offsetx), int(offsety)).release().perform()
    time.sleep(10)
def drag_scroll_by_css(browser, offsetx, offsety):
    scroll = browser.find_element_by_css_selector("div.antiscroll-scrollbar.antiscroll-scrollbar-vertical")
    action = ActionChains(browser)
    action.click_and_hold(scroll).move_by_offset(int(offsetx), int(offsety)).release().perform()
예제 #59
0
파일: browsertest.py 프로젝트: chiller/mint
import os
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
import random
url = "http://galacziendre-mint.jit.su/editor"
import datetime

chromedriver = "/Users/chiller/projects/mint/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.implicitly_wait(5)
driver.get(url)
index = datetime.datetime.now().microsecond % 5
print index

while(True):
    #import ipdb;ipdb.set_trace()
    print "*"
    element = driver.find_elements_by_class_name("drag")[index]
    vector = [random.randint(-20,20),0]
    actionChains = ActionChains(driver)
    actionChains.click_and_hold(element).move_by_offset(*vector).release().perform()
    time.sleep(1 + float(random.randint(100,200)) / 1000 )



driver.quit()