def presenceOfElementLocated(self,locatorMethod,locatorExpression,* arg):
     '''显式等待页面元素出现在DOM中,但并不一定可见,
     存在则返回改页面元素对象'''
     try:
         if self.locationTypeDict.has_key(locatorMethod.lower()):
             self.wait.until(
                 EC.presence_of_all_elements_located((
                     self.locationTypeDictt[locatorMethod.lower()],locatorExpression)))
         else:
             raise TypeError("未找到定位方式,请确认定位方法是否写正确")
     except Exception as e:
         raise e
    def getDriver(self, link_name, driver_selector, css_selector):

        # 드라이버 경로
        chrome = selenium.webdriver.Chrome(driver_selector)

        # 크롬으로 접근할 사이트 링크
        link = chrome.get(link_name)

        # 해당 사이트 접속 후 정상적 연결을 위해 5초 설정
        wait = WebDriverWait(chrome, 3)

        # 제대로 화면이 뜰때까지 기다리기
        # CSS Selector 파라미터로 받으면 객체에서 활용가능
        wait.until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, css_selector)))

        return chrome
Example #3
0
    def unfollow_with_file(self, filename, By=None):
        f = open(filename, "r")
        lines = f.readlines()
        not_following_back = []
        for i in lines:
            not_following_back.append(i[:-1])
        wait = WebDriverWait(self.driver, 10)
        for i in not_following_back:
            url = "https://www.hedieh.com/"+i+"/"
            self.driver.get(url)

            unfollow1 = wait.until(
                EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'button')))
            unfollow1[1].click()
            time.sleep(4)
            path = "/html/"
            unfollow2 = wait.until(
                EC.element_to_be_clickable((By.XPATH, path)))
            unfollow2.click()
            time.sleep(randint(5,13))