Ejemplo n.º 1
0
 def are_download_buttons_displayed(self):
     wait = Wait(self, timeout=3)
     try:
         result = wait.until(expected.visibility_of_all_elements_located((self._download_buttons_locator)))
         return result
     except TimeoutException:
         return False
Ejemplo n.º 2
0
def get_when_all_visible(driver, locator):
  """Return elements by locator when all of them are visible.
 Args: driver (base.CustomDriver), locator (tuple)
 Return: selenium.webdriver.remote.webelement.WebElements
 """
  return (_webdriver_wait(driver).
          until(EC.visibility_of_all_elements_located(locator)))
Ejemplo n.º 3
0
def testShouldWaitUntilAllVisibleElementsAreFoundWhenSearchingForMany(driver, pages):
    pages.load("hidden_partially.html")
    add_visible = driver.find_element_by_id("addVisible")

    add_visible.click()
    add_visible.click()

    elements = WebDriverWait(driver, 2).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "redbox")))
    assert len(elements) == 2
Ejemplo n.º 4
0
def testShouldFailIfNotAllElementsAreVisible(driver, pages):
    pages.load("hidden_partially.html")
    add_visible = driver.find_element_by_id("addVisible")
    add_hidden = driver.find_element_by_id("addHidden")

    add_visible.click()
    add_hidden.click()
    with pytest.raises(TimeoutException):
        WebDriverWait(driver, 0.7).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "redbox")))
Ejemplo n.º 5
0
    def add_col_to_grid(self, col_name):
        filter_fields = self.wait.until(EC.visibility_of_all_elements_located(
            (By.CLASS_NAME, 'filter-fields-label')
        ))

        def is_correct_col(col):
            return col_name in col.get_attribute('for')

        next(filter(is_correct_col, filter_fields)).click()
        self.save_filters()
Ejemplo n.º 6
0
    def test_feedback_filter(self):
        stars = self.browser.find_elements_by_class_name('js-filter-trigger')

        for star in stars:
            star.click()

        feedbacks = self.wait.until_not(EC.visibility_of_all_elements_located(
            (By.CLASS_NAME, '#feedback-list .feedback-block-content')
        ))
        self.assertTrue(feedbacks)
Ejemplo n.º 7
0
    def testShouldWaitUntilAtLeastOneVisibleElementsIsFoundWhenSearchingForMany(self):
        self._loadPage("hidden_partially")
        add_visible = self.driver.find_element_by_id("addVisible")
        add_hidden = self.driver.find_element_by_id("addHidden")

        add_visible.click()
        add_visible.click()
        add_hidden.click()

        elements = WebDriverWait(self.driver, 2).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "redbox")))
        self.assertTrue(len(elements) == 2)
Ejemplo n.º 8
0
 def periodDetail(self):
     periodDetail = []
     while(True):
         WebDriverWait(self.webDriver, 10).until(EC.visibility_of_all_elements_located((By.TAG_NAME,"td")))
         for i in range(len(self.elements("td" ,7))):
             try:
                 periodDetail.append(self.elements("td" ,7)[i].text)
             except:
                 pass
         try:
             self.webDriver.find_element_by_xpath("//a[.='下一页']").click()
         except:
             break
     return periodDetail
Ejemplo n.º 9
0
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time

option = webdriver.ChromeOptions()
option.add_argument("--incognito")

browser  = webdriver.Chrome(executable_path='./chromedriver', chrome_options=option)

browser.get("http://webtoon.daum.net/")

# 페이지로딩 타임아웃
timeout = 10000
try:
    graph = WebDriverWait(browser, timeout).until(EC.visibility_of_all_elements_located((By.XPATH, "//*[@id='dayListTab']")))
except TimeoutException:
    print("Timed out")
    browser.quit()
daycount=1
while daycount <= 7:
    brw_path="//*[@id='dayListTab']/li["+str(daycount)+"]/a"
    browser.find_element_by_xpath(brw_path).click()
    browser.implicitly_wait(2)
    WebDriverWait(browser, timeout).until(EC.visibility_of_all_elements_located((By.XPATH, "//*[@id='cMain']/div[1]/div[1]")))
    time.sleep(1)
    dlc = len(browser.find_elements_by_xpath("//*[@id='dayList1']/li"))
    cnt=1
    while cnt <= dlc:
        thumb_path ="//*[@id='dayList1']/li["+str(cnt)+"]/a/img"
        thumb = browser.find_element_by_xpath(thumb_path)
def exact_all_revs(filename, review_link, min_page=-1):
    opts = Options()
    opts.set_headless()
    opts.set_preference("permissions.default.image", 2)
    assert opts.headless  # Operating in headless mode
    # browser = webdriver.Firefox(options=opts)
    browser = webdriver.Firefox()
    wait = WebDriverWait(browser, 10)
    browser.implicitly_wait(10)
    browser.get(review_link)
    review_zone = browser.find_element_by_id("taplc_location_reviews_list_resp_hr_resp_0")
    # find the first button
    wait.until_not(EC.visibility_of_element_located((By.CLASS_NAME, "tabs_pers_titles")))
    more_buttons = review_zone.find_elements_by_css_selector(
        "div.prw_rup.prw_reviews_text_summary_hsx > div > p > span")
    if len(more_buttons) > 0:
        more_buttons[0].click()
        time.sleep(.1)
    # review_zone.find_element_by_css_selector("div.prw_rup.prw_reviews_text_summary_hsx > div > p > span").click()
    wait.until(EC.visibility_of_all_elements_located(
        (By.CSS_SELECTOR, 'div.ui_column.is-9 > div.prw_rup.prw_reviews_text_summary_hsx > div > p')))
    data = []
    revs = review_zone.find_elements_by_css_selector(
        "div.ui_column.is-9 > div.prw_rup.prw_reviews_text_summary_hsx > div > p")
    dats = review_zone.find_elements_by_css_selector("div.ui_column.is-9 > span.ratingDate")
    rats = review_zone.find_elements_by_css_selector("div.ui_column.is-9 > span.ui_bubble_rating")
    assert len(dats) == len(rats) == len(revs)
    for j, rev in enumerate(revs):
        data.append(
            (dats[j].get_attribute("title"), rev.text, rats[j].get_attribute("class").split()[-1].split("_")[-1]))
    print("- STREAMING REVIEWS:")
    print("\t+ Pulling page 1: %d reviews" % len(data))
    write_csv_a_lines(filename, data)

    num_pages = int(review_zone.find_element_by_css_selector("a.pageNum.last.taLnk").text)
    if min_page > 0:
        num_pages = min_page

    c = len(data)
    i = 1
    while i < num_pages:
        i += 1
        # located next button and clicked on it
        review_zone.find_element_by_css_selector("a.nav.next.taLnk.ui_button.primary").click()
        # wait until the new content is loaded
        try:
            wait.until_not(EC.visibility_of_element_located((By.ID, "taplc_hotels_loading_box_hr_resp_0")))
        except:
            print("Page %d is reloaded" % i - 1)
            time.sleep(1)

        try:
            wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,
                                                              'div.ui_column.is-9 > div.prw_rup.prw_reviews_text_summary_hsx > div > p > span')))
            more_buttons = review_zone.find_elements_by_css_selector(
                "div.prw_rup.prw_reviews_text_summary_hsx > div > p > span")
            if len(more_buttons) > 0:
                more_buttons[0].click()
                time.sleep(.1)
        # review_zone.find_element_by_css_selector("div.prw_rup.prw_reviews_text_summary_hsx > div > p > span").click()
        except:
            # In case of not having a <more> field
            print("Page %d doesn't have the 'more' section" % i)
            time.sleep(1)

        try:
            wait.until(EC.visibility_of_all_elements_located(
                (By.CSS_SELECTOR, 'div.ui_column.is-9 > div.prw_rup.prw_reviews_text_summary_hsx > div > p')))
            data = []
            revs = review_zone.find_elements_by_css_selector(
                "div.ui_column.is-9 > div.prw_rup.prw_reviews_text_summary_hsx > div > p")
            dats = review_zone.find_elements_by_css_selector("div.ui_column.is-9 > span.ratingDate")
            rats = review_zone.find_elements_by_css_selector("div.ui_column.is-9 > span.ui_bubble_rating")
            assert len(dats) == len(rats) == len(revs)
            for j, rev in enumerate(revs):
                data.append((dats[j].get_attribute("title"), rev.text,
                             rats[j].get_attribute("class").split()[-1].split("_")[-1]))

            c += len(data)
            print("\t+ Pulling page %d: %d reviews" % (i, c))
            write_csv_a_lines(filename, data)

        except:
            # In case of not having a <more> field
            print("Page %d doesn't have the 'p' section" % i)
            time.sleep(1)
            data = []
            revs = review_zone.find_elements_by_css_selector(
                "div.ui_column.is-9 > div.prw_rup.prw_reviews_text_summary_hsx > div > p")
            dats = review_zone.find_elements_by_css_selector("div.ui_column.is-9 > span.ratingDate")
            rats = review_zone.find_elements_by_css_selector("div.ui_column.is-9 > span.ui_bubble_rating")
            assert len(dats) == len(rats) == len(revs)
            for j, rev in enumerate(revs):
                data.append((dats[j].get_attribute("title"), rev.text,
                             rats[j].get_attribute("class").split()[-1].split("_")[-1]))
            c += len(data)
            print("\t+ Pulling page %d: %d reviews" % (i, c))
            write_csv_a_lines(filename, data)
    browser.quit()
driver.get('https://www.envisionphysicianservices.com/find-a-career/clinical-job-search?positiontype=225180003#JobList')
           
#initialize dataframe to append into
postlist = pd.DataFrame(columns = ['Title','Hospital','Location1','Location2'])           
           
#loops through pages on website
for p in range(1,52):
    
    #note condition in loop - FIRST TWO PAGES HAVE A TRICKY LOAD SEQUENCE
    if p==1:
        
        #find path of XML element that is the "next" button on page
        xml='//*[@id="cmdNext"]'
        #often, the page opens but loads slowly. selenium will try to induce action (click) before the page is fully loaded
        #this condition makes sure the next button is fully visible before moving to next step
        WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH,xml)))
        
        #each page has 11 boxes, each box has the info from a job listing
        for i in range(1,11):
            
            pager=str(i)
            
            #each XML element iterates nicely, so you can loop through the xml path of each element
            #pull each of the desired fields (selenium pulls elements as a list) and define first list item as string
            
            xml_post='//*[@id="DivResults"]/div[2]/div['+pager+']/div/div[1]/div[1]/div'
            post=driver.find_elements_by_xpath(xml_post)
            post_title=post[0].text
               
            xml_post='//*[@id="DivResults"]/div[2]/div['+pager+']/div/div[2]/div[1]/div/div[1]/div'
            post=driver.find_elements_by_xpath(xml_post)
Ejemplo n.º 12
0
    pwd.send_keys('0b7dba1c77df25bf0')
    enter = driver.find_element_by_name('login')
    enter.click()
except Exception as e:
    print('Что-то пошло не так', e)
    driver.quit()
try:
    driver.find_element_by_css_selector('a[href $="doc=countries"]').click()
    driver.find_element_by_css_selector('a[href $="code=BB"]').click()
    items = driver.find_elements_by_css_selector(
        'i.fa-external-link')  #Находим ссылки ведущие в нове окно
    for item in items:
        current_window = driver.window_handles  #Сохраним текущее
        item.click()
        WebDriverWait(driver,
                      10).until(EC.new_window_is_opened(current_window))
        new_window = driver.window_handles  #Немного волшебства с массивами, чтобы выбрать новое окно
        new_window.remove(driver.current_window_handle)
        driver.switch_to.window(new_window[0])  #Переклоючимся в новое
        WebDriverWait(driver, 10).until(
            EC.visibility_of_all_elements_located(
                (By.TAG_NAME, 'body')))  #Немного подождем
        driver.close()  #Закроем
        driver.switch_to.window(current_window[0])  #Вернемся
    print('Тест пройден')
except Exception as e:
    print('Тест не пройден, ошибка:', e)

driver.quit()
sys.exit()
 def count_campaigns(self):
     self.wait().until(
         expected_conditions.visibility_of_all_elements_located(
             self.locators.CAMPAIGNS_NUMBER))
     num = len(self.driver.find_elements(*self.locators.CAMPAIGNS_NUMBER))
     return num
Ejemplo n.º 14
0
    def wait_for_elements_to_be_visible(self, driver, elements, timeout=''):
        if timeout == '':
            timeout = 10

        el = WebDriverWait(driver, timeout).until(ec.visibility_of_all_elements_located(elements))
Ejemplo n.º 15
0
        three_or_more = soup.find_all('div', class_='zkIadb')
        print("buraya girdi")
        # driver.find_element_by_class_name('zkIadb')
        if len(three_or_more) == 1:
            print("There is more than three element")
            html = driver.page_source
            soup = BeautifulSoup(html, 'html.parser')
            # F find the button which show link to more businesses
            button_href = soup.find_all('a', class_="cMjHbjVt9AZ__button")
            linkToBusinesses = button_href[0]['href']
            print("Found the URL:", linkToBusinesses)
            url = 'https://www.google.com' + linkToBusinesses
            # url = 'https://www.google.com/search?q=burger%20king%20miami&oq=burger+king+miami+&aqs=chrome..69i57.7221j0j9&sourceid=chrome&ie=UTF-8&npsic=0&rflfq=1&rlha=0&rllag=25778920,-80166606,3044&tbm=lcl&rldimm=1507068975858384699&lqi=ChFidXJnZXIga2luZyBtaWFtaSIDiAEBWiAKC2J1cmdlciBraW5nIhFidXJnZXIga2luZyBtaWFtaQ&ved=2ahUKEwiI5fD7puTnAhVE2-AKHaL-BhUQvS4wAHoECAoQFg&rldoc=1&tbs=lrf:!1m4!1u3!2m2!3m1!1e1!1m5!1u15!2m2!15m1!1shas_1wheelchair_1accessible_1entrance!4e2!1m5!1u15!2m2!15m1!1shas_1takeout!4e2!2m1!1e3!3sIAE,lf:1,lf_ui:4&rlst=f#rlfi=hd:;si:;mv:[[25.8660221,-80.1292182],[25.731344000000004,-80.32573479999999]]'
            returnOfDriver = driver.get(url)
            element_buttons = WebDriverWait(driver, 10).until(
                EC.visibility_of_all_elements_located(
                    (By.CSS_SELECTOR, "div.cXedhc")))
            print(url)
            source_of_page = driver.page_source
            soup = BeautifulSoup(source_of_page, 'html.parser')
            # print(soup.text)
            blas = soup.find_all('div', class_='cXedhc')
            # print(blas)

            element_buttons = WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "div.uMdZh")))
            # print(element_buttons)

            if element_buttons:
                # print(element_buttons)
                for el in element_buttons:
Ejemplo n.º 16
0
    def startSteps(self):

        pTxt = "\n-------- Step 'C006' started!!! --------------------------------------------------------------------"
        print(pTxt)

        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        ''' 1. Navigate to staging.getkumbu.com '''
        pTxt = "\n1. Navigate to staging.getkumbu.com\n"
        print(pTxt)
        try:
            self.driver.get(self.url)
            pTxt = "\t\t(Success)\tLoad webpage successfully"
            print(pTxt)
        except:
            pTxt = "\t\t(Error)\tFailed to load webpage"
            print(pTxt)
            self.driver.quit()
            return
        ''' 2. Input email adress: [email protected] '''
        pTxt = "\n2. Input email adress: [email protected]\n"
        print(pTxt)

        try:
            inputs = WebDriverWait(self.driver, 50).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input.kumbu-input")))
        except:
            pTxt = "\t\t(Error)\tCan't find 'Email' and 'Password' Inputs"
            print(pTxt)
            self.driver.quit()
            return

        try:
            email_input = inputs[0]
            email_input.send_keys(self.email)
            pTxt = "\t\t(Success)\tInput email successfully"
            print(pTxt)
        except:
            pTxt = "\t\t(Error)\tFailed to input 'email'"
            print(pTxt)
            self.driver.quit()
            return
        ''' 3. Input password: “kumbu is cool” '''
        pTxt = "\n3. Input password: '******'\n"
        print(pTxt)

        try:
            pwd_input = inputs[1]
            pwd_input.send_keys(self.password)
            pTxt = "\t\t(Success)\tInputted 'Password' successfully"
            print(pTxt)
        except:
            pTxt = "\t\t(Error)\tFailed to input 'Password'"
            print(pTxt)
            self.driver.quit()
            return
        ''' 4. Click Sign in '''
        pTxt = "\n4. Click Sign in\n"
        print(pTxt)
        try:
            submit_btn = WebDriverWait(self.driver, 50).until(
                EC.element_to_be_clickable(
                    (By.CSS_SELECTOR, "input#login-submit")))
            submit_btn.click()
            pTxt = "\t\t(Success)\tClicked 'Sign in' button. Logged in successfully"
            print(pTxt)
        except:
            pTxt = "\t\t(Error)\tFailed to click 'Sign in' button"
            print(pTxt)
            self.driver.quit()
            return
        ''' 5. Click on 'Collection for Test $TEST_NUMBER' '''
        pTxt = "\n5. Click on 'Collection for Test $TEST_NUMBER'\n"
        print(pTxt)
        try:
            collections = WebDriverWait(self.driver, 50).until(
                EC.visibility_of_all_elements_located(
                    (By.CSS_SELECTOR,
                     "div.collection.columns.small-12.medium-3.text-center")))
            flag = False
            for collection in collections:
                if self.collection_txt in collection.text.strip():
                    flag = True
                    break

            if flag:
                try:
                    collection.click()
                    pTxt = "\t\t(Success)\tClicked Successfully"
                    print(pTxt)
                except:
                    pTxt = "\t\t(Error)\tFailed to click"
                    print(pTxt)
                    self.driver.quit()
                    return
            else:
                pTxt = "\t\t(Failure)\tFailed to click"
                print(pTxt)
                self.driver.quit()
                return
        except:
            pTxt = "\t\t(Error)\tFailed to click"
            print(pTxt)
            self.driver.quit()
            return
        ''' 6. Click on the image whose src starts with /item/thumbnail '''
        pTxt = "\n6. Click on the image whose src starts with /item/thumbnail\n"
        print(pTxt)
        try:
            images = WebDriverWait(self.driver, 50).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR,
                     "div.item.columns.small-6.medium-2.upload")))

            if len(images) > 0:
                #images[0].find_element_by_tag_name["a"].click()
                images[0].click()
                pTxt = "\t\t(Success)\tImage is clicked"
                print(pTxt)
            else:
                pTxt = "\t\t(Failure)\tImage can not be clickable"
                print(pTxt)
        except:
            pTxt = "\t\t(Error)\tImage can not be clickable"
            print(pTxt)
            self.driver.quit()
            return
        ''' 7. Verify that 'Appears in 1 collection' is visible '''
        pTxt = "\n7. Verify that 'Appears in 1 collection' is visible\n"
        print(pTxt)

        try:
            txt1 = WebDriverWait(self.driver, 50).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, "div.add-collection-action > h4")))

            if "Appears in 1 collection" in txt1.text.strip():
                pTxt = "\t\t(Success)\t'Appears in 1 collection' is visible"
                print(pTxt)
            else:
                pTxt = "\t\t(Failure\t'Appears in 1 collection' is not visible"

        except:
            pTxt = "\t\t(Error)\t'Appears in 1 collection' is not visible"
            print(pTxt)
            self.driver.quit()
            return
        ''' 8. Verify that an image is visible on the right side '''
        pTxt = "\n8. Verify that an image is visible on the right side\n"
        print(pTxt)

        try:
            img1 = WebDriverWait(self.driver, 50).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR,
                     "div.item-content > div.picture-item > img")))

            pTxt = "\t\t(Success)\tAn image is visible on the right side"
            print(pTxt)

        except:
            pTxt = "\t\t(Error)\tNo image is visible on the right side"
            print(pTxt)
            self.driver.quit()
            return

        self.driver.quit()
        return
Ejemplo n.º 17
0
 def _find_elements(self, loc, timeout=10, poll_frequency=0.5):
     # return WebDriverWait(self._driver,timeout,poll_frequency).until(lambda x:x.find_elements(loc))
     return WebDriverWait(self._driver, timeout, poll_frequency).until(
         EC.visibility_of_all_elements_located((By.XPATH, loc)))
Ejemplo n.º 18
0
 def wait_for_element_visibility(self, locator):
     try:
         return WebDriverWait(self.driver, 10).until(
             EC.visibility_of_all_elements_located(locator))
     except Exception:
         raise Exception('Unsupported locator strategy. :(')
Ejemplo n.º 19
0
 def no_data_error(self):
     no_user_locator = (By.XPATH, self.login_locator.no_data_xpath)
     WebDriverWait(self.driver, 30).until(
         EC.visibility_of_all_elements_located(no_user_locator))
     return self.driver.find_element_by_xpath(
         self.login_locator.no_data_xpath).text
Ejemplo n.º 20
0
products_li = driver.find_elements_by_css_selector("li.grid__item.one-fifth.medium--one-quarter.small--one-half.product-list__item")
links = []
for a in products_li:
    link = a.find_element_by_xpath("./div/a")
    href = link.get_attribute("href")
    links.append(href)



# click for load second page
next_page_button = driver.find_element_by_css_selector("a.pagination-button.pagination-button-next")
driver.execute_script("arguments[0].click();", next_page_button)

# wait for loading product list
element = WebDriverWait(driver, 10).until(
    EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".product-list__item a"))
)
# get all links from products' grid on the second page
li = driver.find_elements_by_css_selector("li.grid__item.one-fifth.medium--one-quarter.small--one-half.product-list__item")
for a in li:
    link = a.find_element_by_xpath("./div/a")
    href = link.get_attribute("href")
    links.append(href)



bottoms_category = {}

for link in links:
    driver.get(link)
    driver.implicitly_wait(3)
Ejemplo n.º 21
0
n=0
for ii in new:
    for i in range(len(ii)):
        if ii[i] not in name_list:
            print(ii[i])
            n += 1
            print(n)
            # 发起一个get请求, 打开一个页面
            url = 'https://baike.baidu.com/item/'+ ii[i]
            driver.get(url)
            try:
                # 等待,未来加载这个元素出来
                hh = '//div[@class="feature-poster-bg"]//div[@class="poster-absolute"]//div[@class="layout"]'
                # hh='/html/body/div[4]/div[1]/div/div[2]/div/style'
                WebDriverWait(driver, 10, 0.5).until(EC.visibility_of_all_elements_located((By.XPATH, hh)))
                photoSrc = driver.find_element_by_xpath(hh).get_attribute("innerHTML")
                # print(photoSrc)
                tt = photoSrc[70:]
                oo = tt[:150]
                print(oo)
                Downloadphoto(oo,ii[i])
            except:
                continue



time.sleep(1)
driver.close()
driver.quit()
Ejemplo n.º 22
0
    def wait_for_elements(self, *elements_locators):
        elements = WebDriverWait(self.browser, 5).until(
            visibility_of_all_elements_located(*elements_locators))

        return elements
Ejemplo n.º 23
0
def main():
    try:
        url = "https://teamtreehouse.com/signin"
        browser_path = " C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"  # noqa E501

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('user-data-dir=' + browser_path)
        chrome_options.add_argument('--profile-directory=Default')
        chrome_options.add_argument('--user-data-dir=C:/Temp/ChromeProfile')

        driver = webdriver.Chrome(options=chrome_options)

        driver.get(url)
        try:
            email_input = WebDriverWait(driver, 10).until(
                EC.visibility_of_all_elements_located(
                    (By.ID, "user_session_email")))  # noqa E501
            email_input[0].send_keys(EMAIL)

            pass_input = driver.find_element_by_id('user_session_password')
            pass_input.send_keys(PASSWORD)
            driver.find_element_by_xpath(
                "//button[@class='button primary']").click()  # noqa E501
        except:  # noqa
            pass

        WebDriverWait(driver, 5)

        link_index = 1  # counter for item from link.txt

        for link in open('links.txt'):
            driver.get(link)

            sections = []

            try:
                WebDriverWait(driver, 10).until(
                    EC.presence_of_element_located(
                        (By.ID, 'syllabus-stages')))  # noqa E501
                elements = driver.find_elements_by_css_selector(
                    "div#syllabus-stages a")  # noqa E501
            except:  # noqa
                pass

            try:
                WebDriverWait(driver, 10).until(
                    EC.presence_of_element_located(
                        (By.ID, 'workshop-steps')))  # noqa E501
                elements = driver.find_elements_by_css_selector(
                    "div#workshop-steps a")  # noqa E501
            except:  # noqa
                pass

            for element in elements:
                res = element.get_attribute("href")
                if res:
                    sections.append(res)

            # Generate folder name and move to it
            parts = link.split('/')
            title = "{:02d}-{}".format(link_index, parts[-1])
            link_index += 1

            if len(sys.argv) > 1:
                move_to_course_directory(title)

            videos = OrderedDict({})
            videos_index = 1

            for section in sections:
                driver.get(section)

                try:
                    WebDriverWait(driver, 10).until(
                        EC.presence_of_element_located(
                            (By.ID, 'video-container')))  # noqa E501
                    video = driver.find_elements_by_xpath(
                        "//source[@type='video/mp4']")[0].get_attribute(
                            "src")  # noqa E501
                    if video:
                        video_title = "{:02d}-{}".format(
                            videos_index,
                            removeReservedChars(
                                driver.find_elements_by_tag_name('h1')
                                [0].text))  # noqa E501

                        videos[video_title] = video  # noqa E501
                        videos_index += 1

                        if len(sys.argv) > 1:
                            # Youtube-dl options
                            options = {
                                'outtmpl': video_title,
                                'external_downloader': EXTERNAL_DL,
                                # ,'verbose': True,
                            }

                            with youtube_dl.YoutubeDL(options) as ydl:
                                ydl.download([video])

                            WebDriverWait(driver, 10)

                except:  # noqa
                    pass

        WebDriverWait(driver, 10)

    except Exception as e:
        print(str(e))
Ejemplo n.º 24
0
def insert_stock_amount(webdriver, stock_amount_2Dlist, waiting_time=30):
    try:
        wait_event = WebDriverWait(webdriver, waiting_time)

        # Retrieve all required web elements (for product with variation)
        if stock_amount_2Dlist[0][SHOPEE_VARIATION_TYPE_INDEX].upper() != "N/A" and \
         stock_amount_2Dlist[0][SHOPEE_VARIATION_DATA_INDEX].upper() != "N/A":
            variation_information_label = wait_event.until(ec.visibility_of_element_located(\
              (By.XPATH, variation_information_label_xpath)))
            variation_information_label.location_once_scrolled_into_view

            variation_table_column_names = wait_event.until(ec.visibility_of_all_elements_located(\
             (By.XPATH, variation_table_column_names_xpath)))
            myproducts_log.debug(
                "Successfully retrieved variation table column names")

            STOCK_COLUMN_INDEX = 0

            for i in range(len(variation_table_column_names)):
                if str(variation_table_column_names[i].text).strip().upper(
                ) != "STOCK":
                    STOCK_COLUMN_INDEX += 1
                else:
                    myproducts_log.debug(
                        "STOCK_COLUMN_INDEX : {}".format(STOCK_COLUMN_INDEX))
                    break

            column_data_input = wait_event.until(ec.visibility_of_all_elements_located(\
             (By.XPATH, column_data_input_xpath)))
            variation_column_data = wait_event.until(ec.visibility_of_all_elements_located(\
             (By.XPATH, variation_column_data_xpath)))
            variation_column_header = wait_event.until(ec.visibility_of_all_elements_located(\
             (By.XPATH, variation_column_header_xpath)))

            myproducts_log.debug("No of column data input (editable & non-editable) : {}".format(\
             len(column_data_input)))
            myproducts_log.debug("No of variation column data : {}".format(
                len(variation_column_data)))
            myproducts_log.debug("No of variation column header : {}".format(
                len(variation_column_header)))

        # Update stock amount for all variations of the same product
        for stock_amount in stock_amount_2Dlist:
            # For product with variation
            if stock_amount[SHOPEE_VARIATION_TYPE_INDEX].upper(
            ) != "N/A" and stock_amount[SHOPEE_VARIATION_DATA_INDEX].upper(
            ) != "N/A":
                stock_row_index = 0
                node_index = 0

                # Check for correct variation combination based on condition of parent node attribute
                while node_index < len(variation_column_data):
                    is_product_variation = False
                    is_found_stock_row_index = False
                    variation_column_data_parent_attribute = get_parent_node_attribute(
                        variation_column_data, node_index)

                    # Check for parent node attribute in the first variation column
                    while "table-row" in variation_column_data_parent_attribute:
                        if variation_column_data[
                                node_index].text in stock_amount[
                                    SHOPEE_VARIATION_DATA_INDEX].split("|"):
                            is_product_variation = True

                        node_index += 1
                        stock_row_index += 1

                        if node_index < len(variation_column_data):
                            variation_column_data_parent_attribute = get_parent_node_attribute(
                                variation_column_data, node_index)

                        # Check for existence of second variation column
                        if "table-cells" in variation_column_data_parent_attribute:
                            stock_row_index -= 1
                            break

                        # Determine the index of stock amount row for variation with one column
                        elif is_product_variation:
                            stock_row_index -= 1
                            is_found_stock_row_index = True
                            break

                    # Check for parent node attribute in the second variation column (if any)
                    while "table-cells" in variation_column_data_parent_attribute:
                        # Determine the index of stock amount row for variation with two columns
                        if is_product_variation and variation_column_data[
                                node_index].text in stock_amount[
                                    SHOPEE_VARIATION_DATA_INDEX].split("|"):
                            is_found_stock_row_index = True
                            break

                        node_index += 1
                        stock_row_index += 1

                        if node_index < len(variation_column_data):
                            variation_column_data_parent_attribute = get_parent_node_attribute(
                                variation_column_data, node_index)

                    if is_found_stock_row_index:
                        break

                myproducts_log.debug(
                    "Correct variation combination is at row index {}".format(
                        stock_row_index))
                row = 0

                # Update stock amount based on its variation combination
                for i in range(STOCK_COLUMN_INDEX, len(column_data_input),
                               len(variation_table_column_names)):
                    if row == stock_row_index:
                        column_data_input[i].clear()
                        column_data_input[i].send_keys(
                            stock_amount[CURRENT_AMOUNT_INDEX])
                        myproducts_log.debug(
                            "Successfully inserted new stock amount")
                        break
                    else:
                        row += 1

            # For product without variation
            else:
                sales_information_label = wait_event.until(ec.visibility_of_element_located(\
                 (By.XPATH, sales_information_label_xpath)))
                sales_information_label.location_once_scrolled_into_view

                stock_amount_textfield = wait_event.until(ec.visibility_of_element_located(\
                 (By.XPATH, stock_amount_textfield_xpath)))
                stock_amount_textfield.clear()
                stock_amount_textfield.send_keys(
                    stock_amount[CURRENT_AMOUNT_INDEX])
                myproducts_log.debug("Successfully inserted new stock amount")

    except Exception as e:
        myproducts_log.error(traceback.print_exc())
Ejemplo n.º 25
0
            else:
                #写入服务码并登陆
                print_log('不需要验证码')
                sendCode(servicePassword)
    #是否登录成功
    result = isLoginSuccess()
    if result is not True:
        print_log('ERROR:网络or验证码or服务密码错误,请重新运行脚本')
        exit_close()
    else:
        print_log('登录成功,正在加载页面...')

    #等待 左侧标签栏加载
    try:
        WebDriverWait(driver, 30).until(
            EC.visibility_of_all_elements_located(
                (By.XPATH, '//a[@class="list-second"]')))
        print_log('左侧标签栏已加载完毕,正在尝试点击"我的信息"...')
    except TimeoutException as timeOut:
        print_log('ERROR:左侧标签栏未找到,已超时:' + str(timeOut))
        print_errorImage('error_wait_list_second')
        exit_close()

    #点击我的信息的标签
    try:
        listSeconds = driver.find_elements_by_xpath(
            "//a[@class='list-second']")
        for listSecond in listSeconds:
            listSecond.click()
        print_log('"所有左侧标签栏打开,正在打开"个人信息"')
    except NoSuchElementException as noElement:
        print_log('ERROR:未找到左侧某个标签,已超时:' + str(noElement))
Ejemplo n.º 26
0


driver.find_element_by_id("Item1-dimensionScreensize-6_1inch").click()
time.sleep(1)
driver.execute_script("window.scrollTo(0,200)")

time.sleep(1)
driver.find_element_by_css_selector(".white > .ir").click()

time.sleep(1)
driver.find_element_by_css_selector("#Item364gb_label > .form-selector-title").click()
# 10 | runScript | window.scrollTo(0,850) | 
driver.execute_script("window.scrollTo(0,850)")
# 11 | click | css=.label | 
WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,'.label')))
driver.find_element_by_css_selector(".label").click()
sleep(4)
driver.find_element_by_name("proceed").click()
sleep(3)
# 13 | click | id=shoppingCart.actions.navCheckout | 
driver.find_element_by_id("shoppingCart.actions.navCheckout").click()
# 14 | mouseOver | id=guest-checkout | 
sleep(3)
driver.find_element_by_id("signIn.guestLogin.guestLogin").click()
#WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.ID,'signIn.guestLogin.guestLogin')))
# 16 | click | css=#guest-checkout > span | 
sleep(3)
driver.find_element_by_css_selector(".as-svgicon-applestorepickup").click()
# 17 | click | css=.as-buttongroup-item:nth-child(1) .form-icon-label | 
sleep(3)
Ejemplo n.º 27
0
    if network_nr == 4:
        continue # Skip liking IG photos - THERE IS AN ERROR

    assume_finnished = False # If two buttons in succession are taking too long to load -> change network
    bot_1.FINNISHED = False
    bot_1.change_network(n=network_nr)
    but_nr = 1
    failed_clicks = 0 # Counts the number of time a button has been clicked on while unclickable (blue loading screen)
    recently_done_names = {}  # To make sure, it doesn't retries the same names several times
    # When the bot (think) it has completed one, temp save it in this dict, if it later reappears
    # don't try to complete it - skip it instead.

    while not bot_1.FINNISHED:
        try:
            print('BUTTON_NR ->', but_nr)
            list_of_like_buttons = WebDriverWait(browser, 15).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".button.blue")))
            list_of_skip_buttons = WebDriverWait(browser, 15).until(EC.visibility_of_all_elements_located((By.LINK_TEXT, "[Skip]")))
            list_of_names = [x.text for x in browser.find_elements_by_css_selector("div > div.container > div.containertitle.remove > h6")]
            print('Found: like buttons: {}\tskip buttons: {}\t names: {}'.format(len(list_of_like_buttons), len(list_of_skip_buttons), list_of_names))
        except TimeoutException as e:
            print('There is not more points to be earned on this network. Error:', e)
            bot_1.FINNISHED = True
            continue
        try:
            list_of_like_buttons[but_nr].click()
        except IndexError:
            # There isn't a eg. fifth button, set but_nr to click to -> 0
            print('- ERROR: IndexError!')
            but_nr = 0
            continue
        except WebDriverException as e:
Ejemplo n.º 28
0
    def get_course_timetable(self, *, test=False, PhantomJS_path='./phantomjs.exe'): #VS根目录为项目文件目录
        if(test):
            time_start = time.clock()

        service_args = ['--load-images=no']
        driver = webdriver.PhantomJS(executable_path=PhantomJS_path, service_args=service_args)
        driver.maximize_window()

        driver.get("http://4m3.tongji.edu.cn/eams/login.action")

        #try:
        #    WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.element_to_be_clickable((By.LINK_TEXT, "统一身份认证登录")))
        #    driver.find_element_by_link_text("统一身份认证登录").click()
        #except:
        #    if(test):
        #        print("Cannot log in 4m3!\n")
        #    return 404

        try:
            WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.visibility_of_any_elements_located((By.ID, "username")))
            driver.find_element_by_id("username").send_keys(self.username)
        except:
            if(test):
                print("Cannot input username!\n")
            return 404

        try:
            WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.visibility_of_any_elements_located((By.ID, "password")))
            driver.find_element_by_id("password").send_keys(self.password)
        except:
            if(test):
                print("Cannot input password!\n")
            return 404

        try:
            WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.element_to_be_clickable((By.NAME, "submit")))
            driver.find_element_by_name("submit").click()
        except:
            if(test):
                print("Cannot click submit button!\n")
            return 404

        try:
            WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.element_to_be_clickable((By.LINK_TEXT, "我的课程")))
            driver.find_element_by_link_text("我的课程").click()
        except:
            if(test):
                print("Cannot click my classes button!\n")
            return 401

        try:
            WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.element_to_be_clickable((By.LINK_TEXT, "我的课表")))
            driver.find_element_by_link_text("我的课表").click()
        except:
            if(test):
                print("Cannot click my timetable button!\n")
            return 500

        try:
            WebDriverWait(driver, 10, 0.001, True).until(expected_conditions.visibility_of_all_elements_located((By.CLASS_NAME, "gridtable")))
        except:
            if(test):
                print("Cannot open timetable!\n")
            return 500

        if(test):
            with open('./' + student.username + '_' + time.strftime("%Y%m%d%H%M%S", time.localtime()) + '.txt', 'w') as html_save:
                html_save.write(driver.page_source)

            driver.save_screenshot('./' + self.username + '_' + time.strftime("%Y%m%d%H%M%S", time.localtime()) + ".png")

            print('%s\n' % str(driver.page_source))
            print("Time of getting timetable of %s: %f\n" % (self.username, time.clock() - time_start))

        return driver.page_source

        driver.quit()
Ejemplo n.º 29
0
driver.implicitly_wait(implicit_delay)

class_url = sys.argv[1]
driver.get(class_url)

login_field = driver.find_element_by_css_selector("input[type='email']")
login_field.send_keys(login)

password_field = driver.find_element_by_css_selector("input[type='password']")
password_field.send_keys(password)

submit_button = driver.find_element_by_css_selector('button')
submit_button.click()

links = WebDriverWait(driver, explicit_delay).until(
    expected_conditions.visibility_of_all_elements_located(
        (By.XPATH, "//a[starts-with(., 'View ')]")))
for link in links:
    link.click()

links = WebDriverWait(driver, explicit_delay).until(
    expected_conditions.visibility_of_all_elements_located(
        (By.XPATH,
         '//a[text()="View"] | //a[text()="Continue"] | //a[text()="Start"]')))
topic_links = []
for link in links:
    topic_links.append(link.get_attribute('href'))

topic = 1
for topic_link in topic_links:
    print('Topic #' + str(topic))
    topic += 1
Ejemplo n.º 30
0
list_sqrt_data=[]

list_beds=[]
list_bath=[]
list_sqrt=[]

page_number2=1
while True and page_number2<26:

    print page_number2, ' current page'

    WebDriverWait(driver, 600).until(
            EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".listing-feature")))

    WebDriverWait(driver, 300).until(
            EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".listing-price")))

    list_features_per_page=driver.find_elements_by_css_selector(".listing-feature")

    house_numbers_per_page=len(list_features_per_page)

    for j in xrange(0,house_numbers_per_page,3):
            list_beds.append(list_features_per_page[j].text)

    for j in xrange(1,house_numbers_per_page,3):
            list_bath.append(list_features_per_page[j].text)

    for j in xrange(2,house_numbers_per_page,3):
            list_sqrt.append(list_features_per_page[j].text)

    list_addresses=driver.find_elements_by_css_selector(".listing-address")
Ejemplo n.º 31
0
import pandas as pd
import numpy as np
import re
import datetime

# %%
# masukkan alamat URL
url = 'https://covid19.jembranakab.go.id'

# mulai otomasi browser menggunakan selenium
driver = webdriver.Firefox()
driver.get(url)

# dan tunggu hingga browser secara sempurna menampilkan tabel yang diinginkan
wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "container")))
print('Ready to scrape')

driver.execute_script("window.scrollTo(0, 1080)")

driver.implicitly_wait(1)

soupJembrana = BeautifulSoup(driver.page_source, 'html5lib')

# %%
Kecamatan_temp = []
seqKecamatan = np.arange(0, 25, 5)
for i, i_fill in enumerate(soupJembrana.findAll('div', class_='table-responsive')):
    isi = i_fill.find('table',class_='table table-striped mx-auto w-auto') \
            .find('tbody').findAll('td')
    for j, j_fill in enumerate(isi):
Ejemplo n.º 32
0
 def wait_page_loaded(self):
     """Wait while current page is fully loaded."""
     self.wait.until(EC.visibility_of_all_elements_located((By.TAG_NAME, 'html')))
Ejemplo n.º 33
0
 def click_first_bid(self):
     WebDriverWait(self.driver, 20).until(
         EC.visibility_of_all_elements_located(locs.bid_button))
     self.driver.find_element(*locs.bid_button).click()
Ejemplo n.º 34
0
 def testShouldFailToFindVisibleElementsWhenExplicitWaiting(self):
     self._loadPage("hidden_partially")
     with self.assertRaises(TimeoutException):
         elements = WebDriverWait(self.driver, 0.7).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "redbox")))
Ejemplo n.º 35
0
 def wait_for_element_located(self, *locator):
     self.driver.wait.until(EC.visibility_of_all_elements_located(locator))
Ejemplo n.º 36
0
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
import random

driver = webdriver.Chrome()
driver.get('http://www.5itest.cn/register?goto=/')
time.sleep(2)
EC.title_contains('注册')
driver.find_element_by_id('register_email')
# 生成随机邮箱
for i in range(5):
    emails = ''.join(random.sample("1234567890", 5))

# 驱动等待5秒 直到查找的元素在页面展示(5秒之内未显示则返回false)
localter = (By.CLASS_NAME, 'controls')
WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located(localter))

# get_attribute方法的使用
email_element = driver.find_element_by_id('register_email')
print(email_element.get_attribute("placeholder"))
email_element.send_keys("*****@*****.**")
print(email_element.get_attribute("value"))
time.sleep(2)
driver.close()

'''
# 注册信息填写
driver.find_element_by_id('register_email').send_keys('*****@*****.**')
parent_element = driver.find_elements_by_class_name('controls')[1]
user_element = parent_element.find_element_by_class_name(
    'form-control').send_keys('TingJio')
Ejemplo n.º 37
0
    def getElement(self, elementInfo, highlight_seconds=5):
        """
        定位单个元素
        :param highlight_seconds:
        :param elementInfo:
        :return:
        """
        webElement = None
        locator_type = elementInfo.locator_type
        locator_value = elementInfo.locator_value
        wait_type = elementInfo.wait_type
        wait_seconds = elementInfo.wait_seconds
        wait_expected_value = elementInfo.wait_expected_value
        if wait_expected_value:
            wait_expected_value = wait_expected_value

        # 查找元素,为了保证元素被定位,都进行显式等待
        if wait_type == Wait_By.TITLE_IS:
            webElement = WebDriverWait(self._driver, wait_seconds).until(
                expected_conditions.title_is(wait_expected_value))
        elif wait_type == Wait_By.TITLE_CONTAINS:
            webElement = WebDriverWait(self._driver, wait_seconds).until(
                expected_conditions.title_contains(wait_expected_value))
        elif wait_type == Wait_By.PRESENCE_OF_ELEMENT_LOCATED:
            webElement = WebDriverWait(self._driver, wait_seconds).until(
                expected_conditions.presence_of_element_located(
                    (locator_type, locator_value)))
        elif wait_type == Wait_By.ELEMENT_TO_BE_CLICKABLE:
            webElement = WebDriverWait(self._driver, wait_seconds).until(
                expected_conditions.element_to_be_clickable(
                    (locator_type, locator_value)))
        elif wait_type == Wait_By.ELEMENT_LOCATED_TO_BE_SELECTED:
            webElement = WebDriverWait(self._driver, wait_seconds).until(
                expected_conditions.element_located_to_be_selected(
                    (locator_type, locator_value)))
        elif wait_type == Wait_By.VISIBILITY_OF:
            webElements = WebDriverWait(self._driver, wait_seconds).until(
                (expected_conditions.visibility_of_all_elements_located(
                    (locator_type, locator_value))))
            if len(webElements) > 0:
                webElement = webElements[0]
        else:
            if locator_type == By.ID:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_id(locator_value))
            elif locator_type == By.NAME:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_name(locator_value))
            elif locator_type == By.LINK_TEXT:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_link_text(
                        locator_value))
            elif locator_type == By.XPATH:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_xpath(locator_value))
            elif locator_type == By.PARTIAL_LINK_TEXT:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_partial_link_text(
                        locator_value))
            elif locator_type == By.CSS_SELECTOR:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_css_selector(
                        locator_value))
            elif locator_type == By.CLASS_NAME:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_class_name(
                        locator_value))
            elif locator_type == By.TAG_NAME:
                webElement = WebDriverWait(self._driver, wait_seconds).until(
                    lambda driver: driver.find_element_by_tag_name(
                        locator_value))
        if not wait_type == Wait_By.TITLE_IS and not wait_type == Wait_By.TITLE_CONTAINS:
            self.highLight(webElement, highlight_seconds)
        return webElement
Ejemplo n.º 38
0
    def runTest(self):
        count = 0
        while True:
            try:
                zigbangUrl = "https://www.zigbang.com/"

                # 0. 직방 웹페이지 접속

                self.driver.get(zigbangUrl)
                time.sleep(1)

                self.driver.add_cookie({
                    'name': 'cookie_sms_apt_app_down',
                    'value': 'true'
                })  # 지도 앱 다운로드 팝업 쿠키 True 값 고정

                self.driver.maximize_window()

                # 1. 아파트 상세화면 진입

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "tit_apartments"))).click()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "room-textfield"))).send_keys(u'테스트할 아파트 명')

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "search_btn"))).click()
                time.sleep(1)

                # 2. 아파트 매물 목록 진입

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.CLASS_NAME, "btn-items-box "))).click()
                time.sleep(2)

                # 3. 아파트 매물 상세화면 진입

                aptitem = self.wait.until(
                    EC.visibility_of_all_elements_located(
                        (By.CLASS_NAME, "card_a-container")))[0]
                # 매물 리스트 최상단 위치 매물

                enterItem = ActionChains(self.driver).click(aptitem)
                enterItem.perform()

                self.moveTab(1)
                time.sleep(1)

                # 5. 신고하기 버튼 클릭

                # self.wait.until(EC.visibility_of_element_located((By.ID, "btn-report")))
                # time.sleep(3)
                #
                # self.wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "layer-close"))).click()
                # time.sleep(1)

                # 6. 문자 보내기

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "btn_contact_agent"))).click()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "phone"))).send_keys("테스트 휴대폰 번호")

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "comment"))).send_keys(u"테스트 문자 내용")

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "btn-inquiry"))).click()

                self.wait.until(EC.alert_is_present()).accept()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "check_agree"))).click()
                time.sleep(3)

                self.driver.find_elements_by_css_selector(
                    "button[class='btn btn-ok']")[1].click()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "btn-inquiry"))).click()

                self.wait.until(EC.alert_is_present()).accept()
                time.sleep(1)

                # 8. 중개사무소 정보 보기 버튼 클릭

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "btn_home_agent"))).click()
                self.moveTab(2)
                self.driver.close()
                self.moveTab(1)

                # 9. 문자 보내기 2

                self.wait.until(
                    EC.visibility_of_all_elements_located(
                        (By.CLASS_NAME, "icon-question2")))[1].click()
                time.sleep(3)

                self.driver.find_elements_by_css_selector(
                    "button[class='btn-close icon-x2']")[1].click()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "phone2"))).send_keys("테스트 휴대폰 번호")

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "comment2"))).send_keys(u"테스트 문자 내용")

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "btn-inquiry2"))).click()

                self.wait.until(EC.alert_is_present()).accept()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "check_agree2"))).click()
                time.sleep(3)

                self.driver.find_elements_by_css_selector(
                    "button[class='btn btn-ok']")[1].click()

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "btn-inquiry2"))).click()

                self.wait.until(EC.alert_is_present()).accept()
                time.sleep(1)

                # 10. 실거래가 및 시세변동 버튼 클릭

                self.wait.until(
                    EC.visibility_of_element_located(
                        (By.ID, "apt_area_info"))).click()
                time.sleep(3)

                self.driver.find_elements_by_css_selector(
                    "button[class='btn-close icon-x2']")[2].click()
                time.sleep(1)

                break

            except Exception:

                if count == 2:
                    raise

                else:
                    traceback.print_exc(file=sys.stdout)
                    print("에러 발생 페이지 URL : ", self.driver.current_url)
                    self.driver.quit()
                    self.setUp()
                    count += 1
    def runTest(self):

        wd = self.driver
        wait = WebDriverWait(wd, 15)

        config_secret = json.loads(open(CONFIG_SETTINGS_COMMON_FILE).read())
        name = config_secret['ACCOUNT']['NAME']
        phone = config_secret['ACCOUNT']['PHONE']
        wording = config_secret['ACCOUNT']['WORDING']
        code = config_secret['ACCOUNT']['CODE']
        normal_email = config_secret['ACCOUNT']['NORMAL_EMAIL']
        normal_password = config_secret['ACCOUNT']['NORMAL_PASSWORD']
        facebook_email = config_secret['ACCOUNT']['FACEBOOK_EMAIL']
        facebook_password = config_secret['ACCOUNT']['FACEBOOK_PASSWORD']
        naver_email = config_secret['ACCOUNT']['NAVER_EMAIL']
        naver_password = config_secret['ACCOUNT']['NAVER_PASSWORD']
        login_email = config_secret['ACCOUNT']['LOGIN_EMAIL']
        login_password = config_secret['ACCOUNT']['LOGIN_PASSWORD']

        sleep(5)

        # TODO - 튜토리얼 확인

        # 첫번째 튜토리얼 화면 다음 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_next'))).click()

        # 두번째 튜토리얼 화면 다음 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_next'))).click()

        # 세번째 튜토리얼 화면 다음 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_next'))).click()

        try:
            # 알림 설정 팝업 나중에 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_negative'))).click()

        except:
            pass

        # TODO - 이메일 회원가입

        # 회원 가입 페이지 진입
        self.driver.execute_script('mobile: deepLink', {
            'url': 'mrt://signup',
            'package': 'com.mrt.ducati'
        })

        sleep(3)

        # 이름 입력
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/input_name'))).send_keys(name)

        # 이메일 주소 입력
        wait.until(
            EC.visibility_of_element_located(
                (By.ID,
                 'com.mrt.ducati:id/input_email'))).send_keys(normal_email)

        # 비밀번호 입력
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/input_password'
                 ))).send_keys(normal_password)

        # 비밀번호 확인 입력
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/input_password_confirm'
                 ))).send_keys(normal_password)

        self.driver.swipe(100, 1600, 100, 150)

        sleep(3)

        # 전체 약관 동의 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/chk_terms_all'))).click()

        # 회원가입 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_signup'))).click()

        # 휴대폰 번호 입력
        wait.until(
            EC.visibility_of_element_located(
                (By.ID,
                 'com.mrt.ducati:id/input_phone_number'))).send_keys(phone)

        # 문자로 인증번호 보내기 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_send'))).click()

        # 인증번호 입력
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/input_code'))).send_keys(code)

        # 인증하기 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_verify'))).click()

        sleep(5)

        # TODO - 이메일 회원가입 확인

        # 프로필 페이지 진입
        try:
            self.driver.execute_script('mobile: deepLink', {
                'url': 'mrt://user',
                'package': 'com.mrt.ducati'
            })
        except:
            pass  # adb 자체 오류로 인해 에러 무시

        sleep(3)

        # 이름/이메일 확인
        normal_name = wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/txt_user_name'))).text
        normal_id = wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/txt_email'))).text

        if normal_name == name:
            pass
        else:
            raise Exception('이메일 회원가입 실패', normal_name, normal_id)

        if normal_id == normal_email:
            pass
        else:
            raise Exception('이메일 회원가입 실패', normal_name, normal_id)

        # TODO - 이메일 로그아웃

        # 설정 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_setting'))).click()

        sleep(2)

        self.driver.swipe(100, 1500, 100, 150)

        sleep(1)

        # 로그아웃 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_logout'))).click()

        sleep(1)

        # TODO - 이메일 로그인

        # 로그인 페이지 진입
        self.driver.execute_script('mobile: deepLink', {
            'url': 'mrt://signin',
            'package': 'com.mrt.ducati'
        })

        sleep(3)

        # 이메일로 로그인 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_email'))).click()

        # 이메일 주소 입력
        wait.until(
            EC.visibility_of_element_located((
                By.XPATH,
                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.EditText'
            ))).send_keys(normal_email)

        # 비밀번호 입력
        wait.until(
            EC.visibility_of_element_located((
                By.XPATH,
                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.EditText'
            ))).send_keys(normal_password)

        # 로그인 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_login'))).click()

        sleep(5)

        # 프로필 페이지 진입
        try:
            self.driver.execute_script('mobile: deepLink', {
                'url': 'mrt://user',
                'package': 'com.mrt.ducati'
            })
        except:
            pass  # adb 자체 오류로 인해 에러 무시

        sleep(3)

        if normal_name == name:
            pass

        else:
            raise Exception('이메일 로그인 실패', normal_name, normal_id)

        if normal_id == normal_email:

            # 설정 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_setting'))).click()

            sleep(2)

            self.driver.swipe(100, 1500, 100, 150)

            sleep(1)

            # 로그아웃 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_logout'))).click()

            sleep(1)

        else:
            raise Exception('이메일 로그인 실패', normal_name, normal_id)

        # TODO - 페이스북 회원가입

        # 회원 가입 페이지 진입
        self.driver.execute_script('mobile: deepLink', {
            'url': 'mrt://signup',
            'package': 'com.mrt.ducati'
        })

        sleep(3)

        # 페이스북으로 회원가입 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_signup_fb'))).click()

        sleep(3)

        try:
            # 페이스북 이메일 입력
            wait.until(
                EC.visibility_of_all_elements_located(
                    (By.CLASS_NAME,
                     'android.widget.EditText')))[0].send_keys(facebook_email)

            # 페이스북 비밀번호 입력
            wait.until(
                EC.visibility_of_all_elements_located(
                    (By.CLASS_NAME, 'android.widget.EditText'
                     )))[1].send_keys(facebook_password)

            # 로그인 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.CLASS_NAME, 'android.widget.Button'))).click()

            # ~님으로 계속 버튼 탭
            wait.until(
                EC.visibility_of_all_elements_located(
                    (By.CLASS_NAME, 'android.widget.Button')))[1].click()

            sleep(3)

            # 전체 약관 동의 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/chk_terms_all'))).click()

            sleep(2)

            # 회원가입 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_signup'))).click()

            sleep(5)

        except:
            # 계속 버튼 탭
            wait.until(
                EC.visibility_of_all_elements_located(
                    (By.CLASS_NAME, 'android.widget.Button')))[0].click()

            # 전체 약관 동의 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/chk_terms_all'))).click()

            sleep(2)

            self.driver.swipe(100, 1500, 100, 150)

            sleep(1)

            # 회원가입 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_signup'))).click()

            sleep(5)

        # TODO - 페이스북 회원가입 확인

        # 프로필 페이지 진입
        self.driver.execute_script('mobile: deepLink', {
            'url': 'mrt://user',
            'package': 'com.mrt.ducati'
        })

        sleep(3)

        # 이름/이메일 확인
        facebook_name = wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/txt_user_name'))).text
        facebook_id = wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/txt_email'))).text

        if facebook_name == 'MRT Kang':
            pass
        else:
            raise Exception('페이스북 회원가입 실패', facebook_name, facebook_id)

        if facebook_id == facebook_email:
            pass
        else:
            raise Exception('페이스북 회원가입 실패', facebook_name, facebook_id)

        # TODO - 페이스북 로그아웃

        # 설정 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_setting'))).click()

        sleep(2)

        self.driver.swipe(100, 1500, 100, 150)

        sleep(1)

        # 로그아웃 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_logout'))).click()

        sleep(1)

        # TODO - 페이스북 로그인

        # 로그인 페이지 진입
        self.driver.execute_script('mobile: deepLink', {
            'url': 'mrt://signin',
            'package': 'com.mrt.ducati'
        })

        sleep(3)

        # 페이스북으로 로그인 버튼 탭
        wait.until(
            EC.visibility_of_element_located(
                (By.ID, 'com.mrt.ducati:id/btn_facebook'))).click()

        sleep(2)

        # 계속 버튼 탭
        wait.until(
            EC.visibility_of_all_elements_located(
                (By.CLASS_NAME, 'android.widget.Button')))[0].click()

        sleep(2)

        # 프로필 페이지 진입
        self.driver.execute_script('mobile: deepLink', {
            'url': 'mrt://user',
            'package': 'com.mrt.ducati'
        })

        sleep(3)

        if facebook_name == 'MRT Kang':
            pass
        else:
            raise Exception('페이스북 회원가입 실패', facebook_name, facebook_id)

        if facebook_id == facebook_email:

            # 설정 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_setting'))).click()

            sleep(2)

            self.driver.swipe(100, 1500, 100, 150)

            sleep(1)

            # 로그아웃 버튼 탭
            wait.until(
                EC.visibility_of_element_located(
                    (By.ID, 'com.mrt.ducati:id/btn_logout'))).click()

            sleep(1)

        else:
            raise Exception('페이스북 회원가입 실패', facebook_name, facebook_id)

        # # TODO - 네이버 회원가입
        #
        # # 회원 가입 페이지 진입
        # self.driver.execute_script('mobile: deepLink', {'url': 'mrt://signup', 'package': 'com.mrt.ducati'})
        #
        # sleep(3)
        #
        # # 네이버로 회원가입 버튼 탭
        # wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_signup_naver'))).click()
        #
        # sleep(3)
        #
        # try:
        #     # 이름 입력
        #     wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/input_name'))).send_keys(name)
        #
        #     # 전체 약관 동의 버튼 탭
        #     wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/chk_terms_all'))).click()
        #
        #     sleep(2)
        #
        #     # 회원가입 버튼 탭
        #     wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_signup'))).click()
        #
        #     sleep(5)
        #
        # except:
        #     try:
        #         # 네이버 로그인 동의 페이지에 위치 하는지 검증
        #         foo = wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.Image')))[1]
        #
        #         self.driver.swipe(100, 1500, 100, 150)
        #
        #         sleep(1)
        #
        #         # 동의하기 버튼 탭
        #         wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.Button')))[1].click()
        #
        #         # 이름 입력
        #         wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/input_name'))).send_keys(name)
        #
        #         # 전체 약관 동의 버튼 탭
        #         wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/chk_terms_all'))).click()
        #
        #         sleep(2)
        #
        #         self.driver.swipe(100, 1500, 100, 150)
        #
        #         sleep(1)
        #
        #         # 회원가입 버튼 탭
        #         wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_signup'))).click()
        #
        #         sleep(5)
        #
        #     except:
        #         # 네이버 이메일 입력
        #         wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.EditText')))[0].send_keys(naver_email)
        #
        #         # 네이버 비밀번호 입력
        #         wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.EditText')))[1].send_keys(naver_password)
        #
        #         # 로그인 상태 유지 버튼 탭
        #         wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'android.widget.CheckBox'))).click()
        #
        #         # 로그인 버튼 탭
        #         wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.Button')))[2].click()
        #
        #         sleep(3)
        #
        #         self.driver.swipe(100, 1500, 100, 150)
        #
        #         # 동의하기 버튼 탭
        #         wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.Button')))[1].click()
        #
        #         # 이름 입력
        #         wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/input_name'))).send_keys(name)
        #
        #         # 전체 약관 동의 버튼 탭
        #         wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/chk_terms_all'))).click()
        #
        #         sleep(2)
        #
        #         self.driver.swipe(100, 1500, 100, 150)
        #
        #         sleep(1)
        #
        #         # 회원가입 버튼 탭
        #         wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_signup'))).click()
        #
        #         sleep(5)
        #
        # # TODO - 네이버 회원가입 확인
        #
        # # 프로필 페이지 진입
        # self.driver.execute_script('mobile: deepLink', {'url': 'mrt://user', 'package': 'com.mrt.ducati'})
        #
        # sleep(3)
        #
        # # 이름/이메일 확인
        # naver_name = wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/txt_user_name'))).text
        # naver_id = wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/txt_email'))).text
        #
        # if naver_name == name:
        #     pass
        # else:
        #     raise Exception('네이버 회원가입 실패', naver_email, naver_id)
        #
        # if  naver_id == naver_email+'@naver.com':
        #     pass
        # else:
        #     raise Exception('네이버 회원가입 실패', naver_email, naver_id)
        #
        # # TODO - 네이버 로그아웃
        #
        # # 설정 버튼 탭
        # wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_setting'))).click()
        #
        # sleep(2)
        #
        # # 로그아웃 버튼 탭
        # wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_logout'))).click()
        #
        # sleep(1)
        #
        # # TODO - 네이버 로그인
        #
        # # 로그인 페이지 진입
        # self.driver.execute_script('mobile: deepLink', {'url': 'mrt://signin', 'package': 'com.mrt.ducati'})
        #
        # sleep(2)
        #
        # # 네이버로 로그인 버튼 탭
        # wait.until(EC.visibility_of_element_located((By.ID, 'com.mrt.ducati:id/btn_naver'))).click()
        #
        # sleep(2)
        #
        # # 네이버 로그인 동의 페이지에 위치 하는지 검증
        # foo = wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.Image')))[1]
        #
        # self.driver.swipe(100, 1500, 100, 150)
        #
        # sleep(2)
        #
        # # 동의하기 버튼 탭
        # wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'android.widget.Button')))[1].click()
        #
        # sleep(5)
        #
        # # 프로필 페이지 진입
        # self.driver.execute_script('mobile: deepLink', {'url': 'mrt://user', 'package': 'com.mrt.ducati'})
        #
        # sleep(3)
        #
        # if naver_name == name:
        #     pass
        # else:
        #     raise Exception('네이버 회원가입 실패', naver_email, naver_id)
        #
        # if  naver_id == naver_email+'@naver.com':
        #     pass
        # else:
        #     raise Exception('네이버 회원가입 실패', naver_email, naver_id)

        # 앱 제거
        self.driver.remove_app('com.mrt.ducati')
Ejemplo n.º 40
0
 def find_elements(driver, locator):
     return WebDriverWait(driver, 15).until(
         ec.visibility_of_all_elements_located(locator),
         message=f"Can't find elements by locator {locator}")
Ejemplo n.º 41
0
    "return arguments[0].scrollIntoView(true);",
    WebDriverWait(driver, 20).until(
        EC.visibility_of_element_located((
            By.XPATH,
            "//table[@class='table table-striped table-bordered dataTable']//th[contains(., 'IP Address')]"
        ))))
# driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table[@class='table table-striped table-bordered dataTable']//th[contains(., 'IP Address')]"))))
select = Select(
    driver.find_element_by_xpath('//select[@name="proxylisttable_length"]'))
select.select_by_visible_text('80')  # select by text
# select.select_by_value('1')# select by value
ips = [
    my_elem.get_attribute("innerHTML")
    for my_elem in WebDriverWait(driver, 5).until(
        EC.visibility_of_all_elements_located((
            By.XPATH,
            "//table[@class='table table-striped table-bordered dataTable']//tbody//tr[@role='row']/td[position() = 1]"
        )))
]
ports = [
    my_elem.get_attribute("innerHTML")
    for my_elem in WebDriverWait(driver, 5).until(
        EC.visibility_of_all_elements_located((
            By.XPATH,
            "//table[@class='table table-striped table-bordered dataTable']//tbody//tr[@role='row']/td[position() = 2]"
        )))
]
driver.quit()
proxies = []
for i in range(0, len(ips)):
    proxies.append(ips[i] + ':' + ports[i])
print(proxies)