Ejemplo n.º 1
0
def log_in(driver, login, password):
	driver.get('http://online.aviso.ua/account2/index.php')
	if not support.wait_for_load(driver, "#inputEmail", 10):
		raise NoSuchElementException()
	support.move_mouse(driver, driver.find_element_by_id('inputEmail'))
	support.send_text(driver.find_element_by_id('inputEmail'), login)
	support.move_mouse(driver, driver.find_element_by_id('inputPassword'))
	support.send_text(driver.find_element_by_id('inputPassword'), password)
	support.move_mouse(driver, driver.find_element_by_css_selector(".controls button"))
	if not support.wait_for_load(driver, ".span8 li:nth-child(3) a", 40):
		raise Exception(ErrorMessage.login)
Ejemplo n.º 2
0
def test_fn(login, password, driver):
    driver.get("http://fn.ua/user/")
    if not support.wait_for_load(driver, "#uemail", 3):
        return "Nope"
    support.move_mouse(driver, driver.find_element_by_id("uemail"))
    support.send_text(driver.find_element_by_id("uemail"), login)
    support.move_mouse(driver, driver.find_element_by_id("upass"))
    support.send_text(driver.find_element_by_id("upass"), password)
    support.move_mouse(driver, driver.find_element_by_name("go_auth"))
    if not support.wait_for_load(driver, "a[href='/newad/']", 15):
        return "Nope"
    return "Yep"
Ejemplo n.º 3
0
def test_olx(login, password, driver):
    driver.get("https://ssl.olx.ua/account/")
    if not support.wait_for_load(driver, "#userEmail", 3):
        return "Nope"
    support.move_mouse(driver, driver.find_element_by_id("userEmail"))
    support.send_text(driver.find_element_by_id("userEmail"), login)
    support.move_mouse(driver, driver.find_element_by_id("userPass"))
    support.send_text(driver.find_element_by_id("userPass"), password)
    support.move_mouse(driver, driver.find_element_by_id("se_userLogin"))
    if not support.wait_for_load(driver, "#topLoginLink > .arrowthindown", 15):
        return "Nope"
    return "Yep"
Ejemplo n.º 4
0
def log_in(driver, login, password):
    driver.get("https://ssl.olx.ua/account/")
    time.sleep(2)
    if not support.wait_for_load(driver, "#userEmail", 8):
        raise NoSuchElementException()
        # authorization ------------------------------------------------------
    support.move_mouse(driver, driver.find_element_by_id("userEmail"))
    support.send_text(driver.find_element_by_id("userEmail"), login)
    support.move_mouse(driver, driver.find_element_by_id("userPass"))
    support.send_text(driver.find_element_by_id("userPass"), password)
    support.move_mouse(driver, driver.find_element_by_id("se_userLogin"))
    if not support.wait_for_load(driver, "#topLoginLink > .arrowthindown", 15):
        raise Exception(ErrorMessage.login)
Ejemplo n.º 5
0
def find_article(driver, urls, title, description, self):
    href, href_art = [], []
    for idx, url in enumerate(urls):
        driver.get(url)
        time.sleep(2)
        elements = []
        if support.wait_for_load(driver, "#adsTable > .tbody > tr", 4):
            elements = driver.find_elements_by_css_selector("#adsTable > .tbody > tr")
        for idx in range(len(elements) / 3):
            try:
                if not support.wait_for_load(
                    driver,
                    "#adsTable > .tbody:nth-child(2) .row-elem:nth-child("
                    + str(idx * 3 + 1)
                    + ") > .td:nth-child(4) > .title > table h3",
                    8,
                ):
                    raise Exception(ErrorMessage.load)
                if (
                    driver.find_element_by_css_selector(
                        "#adsTable > .tbody:nth-child(2) .row-elem:nth-child("
                        + str(idx * 3 + 1)
                        + ") > .td:nth-child(4) > .title > table h3"
                    )
                    .get_attribute("title")
                    .strip()
                    == title.strip()
                ):
                    nth = 1
                    if url == "http://olx.ua/myaccount/moderated/":
                        nth = 2
                    article_url = driver.find_element_by_css_selector(
                        "#adsTable > .tbody:nth-child(2) .row-elem:nth-child("
                        + str(idx * 3 + 1)
                        + ") > .td:nth-child(4) > .title > div a:nth-child("
                        + str(nth)
                        + ")"
                    ).get_attribute("href")
                    driver.get(article_url)
                    time.sleep(2)
                    if not support.wait_for_load(driver, "#textContent", 8):
                        raise Exception(ErrorMessage.load)
                    if compare(driver.find_element_by_css_selector("#textContent > p").text, description):
                        href.append(url)
                        href_art.append(article_url)
                    driver.back()
                    time.sleep(2)
            except NoSuchElementException:
                raise Exception(ErrorMessage.change)
    return href, href_art
Ejemplo n.º 6
0
def test_mir(login, password, driver):
    driver.get("http://mirkvartir.ua/users/login")
    if not support.wait_for_load(driver, "#user_login", 5):
        return "Nope"
        # authorization ------------------------------------------------------
    support.move_mouse(driver, driver.find_element_by_id("user_login"))
    support.send_text(driver.find_element_by_id("user_login"), login)
    support.move_mouse(driver, driver.find_element_by_id("user_password"))
    support.send_text(driver.find_element_by_id("user_password"), password)
    support.move_mouse(driver, driver.find_element_by_id("submit"))
    time.sleep(2)
    if not support.wait_for_load(driver, "#add_notice", 15):
        return "Nope"
    return "Yep"
Ejemplo n.º 7
0
def test_aviso(login, password, driver):
    COUNTER_TIMES = 5
    SLEEP_TIME = 1

    driver.get("http://online.aviso.ua/account2/index.php")
    if not support.wait_for_load(driver, "#inputEmail", 10):
        return "Nope"
    support.move_mouse(driver, driver.find_element_by_id("inputEmail"))
    support.send_text(driver.find_element_by_id("inputEmail"), login)
    support.move_mouse(driver, driver.find_element_by_id("inputPassword"))
    support.send_text(driver.find_element_by_id("inputPassword"), password)
    support.move_mouse(driver, driver.find_element_by_css_selector(".controls button"))
    if not support.wait_for_load(driver, ".span8 li:nth-child(3) a", 40):
        return "Nope"
    return "Yep"
Ejemplo n.º 8
0
def test_address(auth, passw, driver):
    COUNTER_TIMES = 5
    SLEEP_TIME = 1

    driver.get("http://address.ua/")
    try:
        WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "a.userRelatedLink")))
    except:
        driver.get("http://address.ua/")

    count = 0
    while True:
        try:
            driver.execute_script("ShowLoginForm('logindiv');")
            WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input#UserEmail")))
            break
        except:
            time.sleep(SLEEP_TIME)
            count += 1
            if count == COUNTER_TIMES:
                return "Nope"

    driver.find_element_by_css_selector("input#UserEmail").send_keys(auth)
    driver.find_element_by_css_selector("input#Password").send_keys(passw)
    driver.find_element_by_css_selector("input[type='image']").click()
    if not support.wait_for_load(driver, ".userMenu img", 15):
        return "Nope"
    return "Yep"
Ejemplo n.º 9
0
def deactivate_article(self, login, password, driver, write, id):
    # start	--------------------------------------------------
    try:
        log_in(driver, login, password)
        driver.get("http://olx.ua/myaccount/")
        time.sleep(2)
        urls = ["http://olx.ua/myaccount/"]
        write.publish(
            "response_" + id, json.dumps({"progress": "25%", "message": PostingMessage.deactiv_p25})
        )  # ------------------------message---------------------------
        href, href_art = find_article(driver, urls, self["title"], self["description"], self)
        write.publish(
            "response_" + id, json.dumps({"progress": "50%", "message": PostingMessage.deactiv_p50})
        )  # ------------------------message---------------------------
        status = "non deactive"
        for i in range(len(href)):
            driver.get(href[i])
            time.sleep(2)
            if support.wait_for_load(driver, '#adsTable a[href="' + href_art[i] + '"]', 4):
                ar_id = remove_element(driver, href[i], href_art[i])
                ar_id.click()
                time.sleep(1)
                if driver.find_element_by_css_selector("#reasonInnerHeight").is_displayed():
                    if driver.find_element_by_css_selector(
                        "#reasonInnerHeight .reasons > label:nth-child(3)"
                    ).is_displayed():
                        driver.find_element_by_css_selector(
                            "#reasonInnerHeight .reasons > label:nth-child(3) span"
                        ).click()
                    elif driver.find_element_by_css_selector(
                        "#reasonInnerHeight .reasons > label:nth-child(4)"
                    ).is_displayed():
                        driver.find_element_by_css_selector(
                            "#reasonInnerHeight .reasons > label:nth-child(4) span"
                        ).click()
                wait_actions(ar_id)
                status = "deactive"
        if status != "deactive":
            raise Exception(ErrorMessage.not_found)
        write.publish(
            "response_" + id, json.dumps({"progress": "75%", "message": PostingMessage.deactiv_p75})
        )  # ------------------------message---------------------------
        driver.save_screenshot(self["_id"] + "report_olx_ua.png")
        logout(driver)
        write.publish(
            "response_" + id, json.dumps({"progress": "100%", "message": PostingMessage.deactiv_p100})
        )  # ------------------------message---------------------------
        write.publish(
            "response_" + id,
            json.dumps({"progress": "100%", "message": PostingMessage.rander(self["_id"] + "report_olx_ua.png")}),
        )
    except NoSuchElementException, InvalidElementStateException:
        driver.save_screenshot(self["_id"] + "report_olx_ua.png")
        logout(driver)
        raise Exception(ErrorMessage.change)
Ejemplo n.º 10
0
def activate_article(self, login, password, driver, write, id):
    # start	--------------------------------------------------
    try:
        log_in(driver, login, password)
        driver.get("http://olx.ua/myaccount/")
        time.sleep(2)
        urls = ["http://olx.ua/myaccount/archive/"]
        write.publish(
            "response_" + id, json.dumps({"progress": "25%", "message": PostingMessage.activ_p25})
        )  # ------------------------message---------------------------
        href, href_art = find_article(driver, urls, self["title"], self["description"], self)
        write.publish(
            "response_" + id, json.dumps({"progress": "50%", "message": PostingMessage.activ_p50})
        )  # ------------------------message---------------------------
        status = "non active"
        for i in range(len(href)):
            driver.get(href[i])
            time.sleep(2)
            if support.wait_for_load(driver, '#adsTable a[href="' + href_art[i] + '"]', 4):
                ar_id = driver.find_element_by_xpath('//a[@href="' + href_art[i] + '"]/../../../../td[7]//td/a')
                ar_id.click()
                wait_actions(ar_id)
                status = "active"
        if status != "active":
            raise Exception(ErrorMessage.not_found)
        write.publish(
            "response_" + id, json.dumps({"progress": "75%", "message": PostingMessage.activ_p75})
        )  # ------------------------message---------------------------
        driver.save_screenshot(self["_id"] + "report_olx_ua.png")
        logout(driver)
        write.publish(
            "response_" + id, json.dumps({"progress": "100%", "message": PostingMessage.activ_p100})
        )  # ------------------------message---------------------------
        write.publish(
            "response_" + id,
            json.dumps({"progress": "100%", "message": PostingMessage.rander(self["_id"] + "report_olx_ua.png")}),
        )
    except NoSuchElementException, InvalidElementStateException:
        driver.save_screenshot(self["_id"] + "report_olx_ua.png")
        logout(driver)
        raise Exception(ErrorMessage.change)
Ejemplo n.º 11
0
def post(self, login, password, driver, write, id):
    # variables -----------------------------------------
    try:
        adv_type = int(self["adv_type"])
        category = int(self["building"][0])
        try:
            subcategory = int(self["building"][1]) + 1
        except:
            subcategory = 0
        currency = int(self["currency"]) + 1
        if self["type"] == "":
            house_type = 0
        else:
            house_type = int(self["type"]) + 1
        loc1 = int(self["location"][0])
        loc2 = 9 - int(self["location"][1])
        district = Map_olx_directs[loc1][loc2]
        if self["location"][2] == "":
            city = Map_olx_city[loc1][loc2]
        else:
            city = self["location"][2]

        map_address = city + u", Киевская область"
    except:
        raise Exception(ErrorMessage.fields)
        # start	--------------------------------------------------
    try:
        log_in(driver, login, password)
        time.sleep(2)
        write.publish(
            "response_" + id, json.dumps({"progress": "25%", "message": PostingMessage.post_p25})
        )  # ------------------------message---------------------------
        # add -----------------------------------------------------------------
        if not support.wait_for_load(driver, "#postNewAdLink", 10):
            raise NoSuchElementException()
        support.move_mouse(driver, driver.find_element_by_id("postNewAdLink"))
        time.sleep(2)
        # title ----------------------------------------------------------------
        if not support.wait_for_load(driver, "#add-title", 10):
            raise NoSuchElementException()
        support.move_mouse(driver, driver.find_element_by_id("add-title"))
        driver.find_element_by_id("add-title").send_keys(self["title"])
        time.sleep(2)
        support.move_mouse(driver, driver.find_element_by_id("targetrenderSelect1-0"))
        # select catecory -----------------------------------------------------------------------
        if not support.wait_for_load(driver, "#cat-1", 15):
            raise NoSuchElementException()
        support.move_mouse(driver, driver.find_element_by_id("cat-1"))
        if not support.wait_for_load(
            driver, '#category-1 a[data-category="' + chose_flat[adv_type][category] + '"]', 2
        ):
            raise NoSuchElementException()
        support.move_mouse(
            driver,
            driver.find_element_by_css_selector(
                '#category-1 a[data-category="' + chose_flat[adv_type][category] + '"]'
            ),
        )

        if support.wait_for_load(
            driver, "#category-" + chose_flat[adv_type][category] + " li:nth-child(" + str(subcategory) + ")", 2
        ):
            support.move_mouse(
                driver,
                driver.find_element_by_css_selector(
                    "#category-" + chose_flat[adv_type][category] + " li:nth-child(" + str(subcategory) + ")"
                ),
            )
        if not support.wait_for_load(driver, "#parameter-div-price input.text", 10):
            raise NoSuchElementException()
        write.publish(
            "response_" + id, json.dumps({"progress": "50%", "message": PostingMessage.post_p50})
        )  # ------------------------message---------------------------
        # price ----------------------------------------------
        driver.execute_script(
            "document.getElementById('targetid_private_business').getElementsByTagName('dd')[0].getElementsByTagName('ul')[0].style.display = 'block';"
        )
        support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-price input.text"))
        support.send_text(driver.find_element_by_css_selector("#parameter-div-price input.text"), self["price"])
        support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-price dl dt a"))
        support.move_mouse(
            driver, driver.find_element_by_css_selector("#parameter-div-price dl li:nth-child(" + str(currency) + ")")
        )
        # options -------------------------------------------------------------------------------------
        if category in (0, 2):
            if support.wait_for_load(driver, "#parameter-div-number_of_rooms input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-number_of_rooms input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-number_of_rooms input"), self["rooms"]
                )
            if support.wait_for_load(driver, "#parameter-div-total_area input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-total_area input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-total_area input"), self["space"][0]
                )
            if support.wait_for_load(driver, "#parameter-div-total_living_area input", 1):
                support.move_mouse(
                    driver, driver.find_element_by_css_selector("#parameter-div-total_living_area input")
                )
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-total_living_area input"), self["space"][1]
                )
            if support.wait_for_load(driver, "#parameter-div-kitchen_area input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-kitchen_area input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-kitchen_area input"), self["space"][2]
                )
            if house_type and support.wait_for_load(driver, "#parameter-div-house_type dl dt a", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-house_type dl dt a"))
                support.move_mouse(
                    driver,
                    driver.find_element_by_css_selector(
                        "#parameter-div-house_type dl li:nth-child(" + str(house_type) + ")"
                    ),
                )
            if support.wait_for_load(driver, "#parameter-div-floor input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-floor input"))
                support.send_text(driver.find_element_by_css_selector("#parameter-div-floor input"), self["floor"][0])
            if support.wait_for_load(driver, "#parameter-div-total_floors input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-total_floors input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-total_floors input"), self["floor"][1]
                )
            if support.wait_for_load(driver, "#parameter-div-rent_from input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-rent_from input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-rent_from input"), self["rent_from"]
                )
            if support.wait_for_load(driver, "#parameter-div-total_rooms_in_flat input", 1):
                support.move_mouse(
                    driver, driver.find_element_by_css_selector("#parameter-div-total_rooms_in_flat input")
                )
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-total_rooms_in_flat input"), self["rooms"]
                )
        if category in (1, 3):
            support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-distance_from_city input"))
            support.send_text(
                driver.find_element_by_css_selector("#parameter-div-distance_from_city input"), self["remote"]
            )
            if support.wait_for_load(driver, "#parameter-div-land_area input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-land_area input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-land_area input"), self["space"][0]
                )
            if support.wait_for_load(driver, "#parameter-div-house_area input", 1):
                support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-house_area input"))
                support.send_text(
                    driver.find_element_by_css_selector("#parameter-div-house_area input"), self["space"][0]
                )
        if category == 5:
            support.move_mouse(driver, driver.find_element_by_css_selector("#parameter-div-area input"))
            support.send_text(driver.find_element_by_css_selector("#parameter-div-area input"), self["space"][0])
            # descriptions + personal ------------------------------------------------------------------------
            # support.move_mouse(driver, driver.find_element_by_css_selector('#private-business-div dl dt a'))
            # support.move_mouse(driver, driver.find_element_by_css_selector('#private-business-div dl li:nth-child(2) a'))
        driver.find_element_by_css_selector("#targetid_private_business dt a").click()
        driver.find_element_by_css_selector("#private-business-div dl li:nth-child(2) a").click()
        support.move_mouse(driver, driver.find_element_by_css_selector("#add-description"))
        driver.find_element_by_css_selector("#add-description").send_keys(
            self["description"] + " z " + str(int(round(time.time() * 1000)))
        )
        write.publish(
            "response_" + id, json.dumps({"progress": "75%", "message": PostingMessage.post_p75})
        )  # ------------------------message---------------------------
        # imeges ---------------------------------------------------
        support.move_mouse(driver, driver.find_element_by_css_selector("#show-gallery-html"))
        for idx, val in enumerate(self["img_src"]):
            if support.wait_for_load(driver, "#htmlbutton_" + str(idx + 1) + " input", 1):
                driver.find_element_by_css_selector("#htmlbutton_" + str(idx + 1) + " input").send_keys(
                    self["_id"] + val
                )
                # locations --------------------------------------------------------------------------
        attempt = 0
        while attempt < 5:
            try:
                support.move_mouse(driver, driver.find_element_by_css_selector("#mapAddress"))
                driver.find_element_by_css_selector("#mapAddress").clear()
                support.send_text_long(driver.find_element_by_css_selector("#mapAddress"), map_address)
                time.sleep(0.5)
                if loc1 == 1:
                    if support.wait_for_load(driver, "#autosuggest-geo-ul li:nth-child(1) > a", 2):
                        support.move_mouse(
                            driver, driver.find_element_by_css_selector("#autosuggest-geo-ul li:nth-child(1) > a")
                        )
                    else:
                        raise Exception(ErrorMessage.location)
                if loc1 == 0:
                    if support.wait_for_load(driver, "#autosuggest-geo-ul li:nth-child(1) > a", 2):
                        driver.execute_script(
                            'document.getElementById("autosuggest-geo-ul").getElementsByTagName("li")[0].className = "hover"'
                        )
                        time.sleep(1)
                        driver.execute_script(
                            'document.getElementById("autosuggest-geo-ul").getElementsByTagName("li")[0].className = "hover"'
                        )
                        driver.find_element_by_css_selector(
                            "#autosuggest-geo-ul li:nth-child(1) > .geo-districts-ul li:nth-child("
                            + str(loc2 + 1)
                            + ") > a"
                        ).click()
                    else:
                        raise Exception(ErrorMessage.location)
            except:
                attempt += 1
            else:
                break
        if attempt >= 5:
            raise Exception(ErrorMessage.location)
            # phone + skype + name ----------------------------------------------------------------------
        support.move_mouse_dc(driver, driver.find_element_by_css_selector("#add-person"))
        support.send_text(driver.find_element_by_css_selector("#add-person"), self["per_name"])
        support.move_mouse_dc(driver, driver.find_element_by_css_selector("#add-phone"))
        support.send_text(driver.find_element_by_css_selector("#add-phone"), self["per_telephone"])
        support.move_mouse_dc(driver, driver.find_element_by_css_selector("#add-skype"))
        support.send_text(driver.find_element_by_css_selector("#add-skype"), self["skype"])
        write.publish(
            "response_" + id, json.dumps({"progress": "100%", "message": PostingMessage.post_p100})
        )  # ------------------------message---------------------------
        # save+screenshot-------------------------------------------------------------
        driver.save_screenshot(self["_id"] + "report_olx_ua.png")
        time.sleep(2)
        write.publish(
            "response_" + id,
            json.dumps({"progress": "100%", "message": PostingMessage.rander(self["_id"] + "report_olx_ua.png")}),
        )
        attempt = 0
        while attempt < 5:
            try:
                driver.find_element_by_css_selector("#save").click()
                time.sleep(4)
                if not support.wait_for_load(driver, "#addAnotherAd", 20):
                    driver.save_screenshot(self["_id"] + "report_olx_ua.png")
                    logout(driver)
                    raise Exception(ErrorMessage.wrong)
                driver.save_screenshot(self["_id"] + "report_olx_ua.png")
                break
            except:
                attempt += 1
        logout(driver)
    except NoSuchElementException, InvalidElementStateException:
        driver.save_screenshot(self["_id"] + "report_olx_ua.png")
        logout(driver)
        raise Exception(ErrorMessage.change)
Ejemplo n.º 12
0
def manage_article(self, driver, login, password, write, id, comm = 'id'):
	urls = ['http://online.aviso.ua/account2/myads.php']
	try:
		log_in(driver, login, password)
		if comm in ['status', 'id']:
			write.publish("response_" + id, json.dumps({"progress": "25%","message": PostingMessage.stat_p25}))#------------------------message---------------------------	
		else:
			write.publish("response_" + id, json.dumps({"progress": "25%","message": PostingMessage.del_p25}))#------------------------message---------------------------	
			
		for url in urls:
			driver.get(url)
			time.sleep(2)
			'''
			for i, el in enumerate(driver.find_elements_by_xpath("//*[@id='pagination']/li/a")):
				if el.get_attribute('href') not in urls:
					urls.append(el.get_attribute('href'))
			'''
	 		
			elements = []
			status = ''
			id_d = ''
			if support.wait_for_load(driver, 'a[href*="newad_step4.php?"]', 10):
				elements = driver.find_elements_by_css_selector('a[href*="newad_step4.php?"]')
			#elements_text = driver.find_elements_by_css_selector("span[style='display:block;height:50px;width:300px']")
			for _id in range(len(elements)):
				try:	
					if not support.wait_for_load(driver, 'a[href*="newad_step4.php?"]', 10):
						raise NoSuchElementException()	
					else:
						elements = driver.find_elements_by_css_selector('a[href*="newad_step4.php?"]')
					_url = getAttribute(driver, elements[_id], 'href')
					driver.get('http://online.aviso.ua/account2/'+_url)
					if not support.wait_for_load(driver, ".controls .input-large", 10):
						raise NoSuchElementException()	
					price = getAttribute(driver, driver.find_element_by_css_selector('.controls .input-large'), 'value')			
					
					text = driver.execute_script("var el = document.getElementById('inputAdText'); return el.innerHTML;")
					driver.back()	
					if compare(price, self['price'], 'del') and compare(text, self['description']):
						try:
							img_src = driver.find_element_by_xpath("/html/body/div/div[7]/div[2]/table/tbody/tr["+str(_id+1)+"]/td[5]/a[4]/img").get_attribute('src')
						except:
							img_src = driver.find_element_by_xpath("/html/body/div/div[7]/div[2]/table/tbody/tr["+str(_id+1)+"]/td[5]/a[3]/img").get_attribute('src')
						try:
							id_d = driver.find_element_by_xpath("/html/body/div/div[7]/div[2]/table/tbody/tr["+str(_id+1)+"]/td[5]/a[6]").get_attribute('href')
						except:
							id_d = driver.find_element_by_xpath("/html/body/div/div[7]/div[2]/table/tbody/tr["+str(_id+1)+"]/td[5]/a[5]").get_attribute('href')
						if 'deactivate.png' in img_src:
							status = 'active'
						else:
							status = 'noactive'						
						if comm in ['status', 'id']:
							write.publish("response_" + id, json.dumps({"progress": "50%","message": PostingMessage.stat_p50}))#------------------------message---------------------------	
						else:
							write.publish("response_" + id, json.dumps({"progress": "50%","message": PostingMessage.del_p50}))#------------------------message---------------------------		
	
						if comm == 'del':
							driver.get('http://online.aviso.ua/account2/myads.php')
							if not support.wait_for_load(driver, 'a[href*="newad_step4.php?"]', 10):
								raise NoSuchElementException()	
							driver.get(id_d)
							time.sleep(2)
							write.publish("response_" + id, json.dumps({"progress": "75%","message": PostingMessage.del_p75}))#------------------------message----------	
							if driver.current_url == 'http://online.aviso.ua/account2/myads.php?result=del_ok':
								logout(driver)
								write.publish("response_" + id, json.dumps({"progress": "100%","message": PostingMessage.del_p100}))#------------------------message---------------------------
								return 0
							else:
								driver.save_screenshot(self["_id"] + 'report_aviso.png')
								logout(driver)
								raise Exception(ErrorMessage.change)

						if comm == 'status':
							write.publish("response_" + id, json.dumps({"progress": "75%","message": PostingMessage.del_p75}))#------------------------message---------------------------	
							logout(driver)
							return status
						if comm == 'id':
							write.publish("response_" + id, json.dumps({"progress": "75%","message": PostingMessage.del_p75}))#------------------------message---------------------------	
							logout(driver)
							return id_d		
			
				except NoSuchElementException:		
					raise Exception(ErrorMessage.change)
		logout(driver)
		return 1
				
	except Exception as e:
		driver.save_screenshot(self["_id"] + 'report_aviso.png')
		logout(driver)
		raise Exception(ErrorMessage.wrong)				
Ejemplo n.º 13
0
def post(self, login, password, driver, write, id):
	COUNT_TIMES = 10
	
	try:	
		log_in(driver, login, password)
		time.sleep(2)		
		per_tel = self['per_telephone'][1:]
		write.publish("response_" + id, json.dumps({"progress": "25%","message": PostingMessage.post_p25}))#------------------------message---------------------------
		support.move_mouse(driver, driver.find_element_by_css_selector(".span8 li:nth-child(3) a"))
		if not support.wait_for_load(driver, ".form-horizontal label:nth-child(1)", 20):
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
			raise NoSuchElementException()
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal label:nth-child(1)"))
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal button"))

		n1 = choose_section[int(self["adv_type"])][int(self["building"][0])]
		#if self["adv_type"] == '0' and self["building"][0] in ('0', '2') and self["building"][1] == '2':
		#	n1 = '4'	 
		n2 = 1
		if self["building"][0] in ('1','3'):
			n2 = int(self["building"][0])
			if self["building"][0] == '3':
				n2 = 2
		if self["location"][0] == '0':
			n3 = int(self["location"][1]) + 1
		else:
			n3 = int(self["location"][1]) + 12
		if n3 > 36 - 25 * (1 ^ int(self["adv_type"])):
			n3 = 37 - 26 * (1 ^  int(self["adv_type"]))
		n4 = currency[int(self["currency"])]
		n5 = (int(self["rooms"]) + 1)	if self['rooms'] != '' else 0
		print n5
		if n5 > 6:
			n5 = 6
		if not support.wait_for_load(driver, ".form-horizontal label:nth-child(" + n1 + ")", 10):
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
			raise NoSuchElementException()
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal label:nth-child(" + n1 + ")"))
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal button[type='submit']"))

		if not support.wait_for_load(driver, ".form-horizontal label:nth-child(" + str(n2) + ")", 10):
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
			raise NoSuchElementException()
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal label:nth-child(" + str(n2) + ")"))
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal button[type='submit']"))
		write.publish("response_" + id, json.dumps({"progress": "50%","message": PostingMessage.post_p50}))#------------------------message---------------------------
		if not support.wait_for_load(driver, "input[name='ad_title']", 20):
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
			raise NoSuchElementException()
		support.move_mouse(driver, driver.find_element_by_css_selector("input[name='ad_title']"))
		support.send_text(driver.find_element_by_css_selector('input[name="ad_title"]'), self["title"])

		support.move_mouse(driver, driver.find_element_by_css_selector("textarea[name='ad_text']"))
		support.send_text(driver.find_element_by_css_selector('textarea[name="ad_text"]'), self["description"])
		if support.wait_for_load(driver, '#adDistrict', 2):
			support.move_mouse(driver, driver.find_element_by_css_selector('#adDistrict'))
			driver.find_element_by_css_selector('#adDistrict option[value="' + str(n3) + '"]').click()

		support.move_mouse(driver, driver.find_element_by_css_selector("input[name='ad_price']"))
		support.send_text(driver.find_element_by_css_selector('input[name="ad_price"]'), self["price"])

		support.move_mouse(driver, driver.find_element_by_css_selector("select[name='ad_currency']"))
		driver.find_element_by_css_selector('select[name="ad_currency"] option[value="' + str(n4) + '"]').click()

		if self["building"][0] == '0':
			support.move_mouse(driver, driver.find_element_by_xpath("//*[@id='adRooms']"))
			driver.find_element_by_css_selector('#adRooms option:nth-child(' + str(n5) + ')').click()
	
			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='space_all']"))
			support.send_text(driver.find_element_by_css_selector('input[name="space_all"]'), self["space"][0])
			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='space_live']"))
			support.send_text(driver.find_element_by_css_selector('input[name="space_live"]'), self["space"][1])
			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='space_kitch']"))
			support.send_text(driver.find_element_by_css_selector('input[name="space_kitch"]'), self["space"][2])

			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='floor']"))
			support.send_text(driver.find_element_by_css_selector('input[name="floor"]'), self["floor"][0])
			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='floors']"))
			support.send_text(driver.find_element_by_css_selector('input[name="floors"]'), self["floor"][1])
		if self["building"][0] == '1':
			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='space_all']"))
			support.send_text(driver.find_element_by_css_selector('input[name="space_all"]'), self["space"][0])
			if self["adv_type"] == '1':
				support.move_mouse(driver, driver.find_element_by_css_selector("input[name='space_live']"))
				support.send_text(driver.find_element_by_css_selector('input[name="space_live"]'), self["space"][1])
				support.move_mouse(driver, driver.find_element_by_css_selector("input[name='floors']"))
				support.send_text(driver.find_element_by_css_selector('input[name="floors"]'), self["floor"][1])
		if self["building"][0] == '3':
			support.move_mouse(driver, driver.find_element_by_css_selector("input[name='space_all']"))
			support.send_text(driver.find_element_by_css_selector('input[name="space_all"]'), self["space"][0])
		write.publish("response_" + id, json.dumps({"progress": "75%","message": PostingMessage.post_p75}))#------------------------message---------------------------
		support.move_mouse(driver, driver.find_element_by_css_selector("input[name='op_code1']"))
		support.send_text(driver.find_element_by_css_selector('input[name="op_code1"]'), per_tel[:2])
		support.move_mouse(driver, driver.find_element_by_css_selector("input[name='phone_num1']"))
		support.send_text(driver.find_element_by_css_selector('input[name="phone_num1"]'), per_tel[2:9])
		support.move_mouse(driver, driver.find_element_by_css_selector("#inputContact"))
		support.send_text(driver.find_element_by_css_selector('#inputContact'), self["per_name"])
		support.move_mouse(driver, driver.find_element_by_css_selector(".form-horizontal button[type='submit']"))

		if not support.wait_for_load(driver, "input[type='file']", 40):
			raise NoSuchElementException()
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
		for src in self["img_src"]:	
			try:
				support.send_text(driver.find_element_by_css_selector("input[type='file']"), self["_id"] + src)
			 	support.move_mouse(driver, driver.find_element_by_css_selector("input[type='submit']"))
			except:
				time.sleep(5)
		if not support.wait_for_load(driver, ".btn-large", 10):
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
			raise NoSuchElementException()
		support.move_mouse(driver, driver.find_element_by_css_selector(".btn-large"))	
		if not support.wait_for_load(driver, ".btn-warning", 10):
			driver.save_screenshot(self["_id"] + 'report_aviso.png')
			logout(driver)
			raise NoSuchElementException()
		support.move_mouse(driver, driver.find_element_by_css_selector(".btn-warning"))
		print "Done!"
		write.publish("response_" + id, json.dumps({"progress": "100%","message": PostingMessage.post_p100})) #------------------------message---------------------------
		write.publish("response_" + id, json.dumps({"progress": "100%","message": PostingMessage.rander(self["_id"] + 'report_aviso.png')}))	
		logout(driver)
	except NoSuchElementException, InvalidElementStateException:
		#driver.save_screenshot(self[self["_id"]] + 'report_mirkvartir.png')
		driver.save_screenshot(self["_id"] + 'report_aviso.png')
		logout(driver)
		print 'picture'
		raise Exception(ErrorMessage.change)