滑動找到元素

1.while 循環
while True:
    try:
        if driver.find_element_by_xpath("xxx"):
             break
        else:
            driver.driver.swipe(sx, sy, sx, ey)
2.遞歸
def fine_ele(driver):
    if driver.find_element_by_xpath("xxx")
        return True
    else:
        driver.swipe(sx, sy, sx, ey)
        fine_ele(driver)

上面這樣寫會報,元素不存在
修改如下:

    def swipe_up(self):
        s = self.driver.get_window_size()
        x1 = s['width'] * 0.5  # x座標
        y1 = s['height'] * 0.75  # 起點y座標
        y2 = s['height'] * 0.25  # 終點y座標
        print('手機的尺寸是: ', s)
        self.driver.swipe(x1, y1, x1, y2, 500)

    def find_element_up(self, locate_element):
        _source_list = self.driver.page_source
        #print(_source_list)
        if locate_element in _source_list:
            return True
        else:
            self.swipe_up()
            self.find_element_up(locate_element)
      調用函數如下:
    def scroll_game_book_to_head(self):
        '''將新遊預約遊戲滑動到測試遊戲模塊'''
        _locate_element = '新遊預約'
        self.find_element_up(_locate_element)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章