Esempio n. 1
0
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(
    "file:///home/dominik/workspace/kurs_selenium/podst_sel_1/demos/doubleClick.html"
)
driver.maximize_window()

button = driver.find_element_by_id('bottom')
webdriver.ActionChains(driver).context_click(button).perform()

time.sleep(1)
driver.quit()
Esempio n. 2
0
    def send_cv(self):
        browser.execute_script(
            "window.document.getElementById('modal_window').scroll(0,200)")
        #  global input_to_cv_application
        try:
            time.sleep(2)
            select_dont_leave_the_site = browser.find_element_by_xpath(
                "//div[@id='modal_content']/div[@id='buttons']/input[@class='bttn']"
            )
            actions = webdriver.ActionChains(browser)
            actions.click(select_dont_leave_the_site)
            actions.perform()
        except:
            pass

        try:
            time.sleep(2)
            select_father_resume = browser.find_element_by_xpath(
                "//div[@id='CVRadioPlaceHolder']/label[@id='korotVersionNumLabel8088450']"
            )
            actions = webdriver.ActionChains(browser)
            actions.click(select_father_resume)
            actions.perform()
        except:
            pass
        try:
            time.sleep(2)
            browser.execute_script(
                "window.document.getElementById('modal_window').scroll(0,500)")
            select_from_options = browser.find_element_by_xpath(
                "//div[@class='UpdateGroup FilterQuestions']/div[@class='UpdateElement']/select[@class='AnswerSelect InputFix']"
            )
            exit_the_question = browser.find_element_by_xpath(
                "//div[@id='buttons']/input[@class='bttn CancelButton']")
            actions = webdriver.ActionChains(browser)
            actions.click(exit_the_question)
            actions.perform()

        except Exception as e:
            print(e, "didn't work out")
            pass

        try:
            time.sleep(2)
            select_array_selector = browser.find_elements_by_class_name(
                "AnswerSelect InputFix")[0]
            actions = webdriver.ActionChains(browser)
            actions.click(select_array_selector)
            actions.perform()
        except:
            pass

        try:
            input_to_cv_application = browser.find_element_by_xpath(
                "//div[@id='buttons']/input[@class='bttn blue SaveButton WithCancel']"
            )
            time.sleep(4)
        except Exception:
            time.sleep(4)
            try:
                error_fix = browser.find_element_by_xpath(
                    "//div[@class='Show']/div[@id='modal_title']/div[@id='modal_content']/input[@class='bttn']"
                )
                actions = webdriver.ActionChains(browser)
                actions.click(error_fix)
                actions.perform()
            except Exception:
                pass

        try:
            error_fix = browser.find_element_by_xpath(
                "//div[@id='modal_content']/input[@class='bttn']")
            actions = webdriver.ActionChains(browser)
            actions.click(error_fix)
            actions.perform()
        except Exception:
            pass

        try:
            similar_jobs = browser.find_element_by_xpath(
                "//div[@class='MultiSendRadioPlaceHolder']/label[@for='isMultiSendN']"
            )
            actions = webdriver.ActionChains(browser)
            actions.click(similar_jobs)
            actions.perform()
        except Exception:
            pass
        try:
            actions = webdriver.ActionChains(browser)
            actions.click(input_to_cv_application)
            actions.perform()
        except Exception:
            pass
from selenium import webdriver


browser = webdriver.Chrome()
browser.get('http://www.porters.vip/captcha/sliders.html')
hover = browser.find_element_by_css_selector('.hover')

action = webdriver.ActionChains(browser)
action.click_and_hold(hover).perform()  
action.move_by_offset(340, 0)  
action.release().perform() 
Esempio n. 4
0
 def make_context_click(self, target):
     action = webdriver.ActionChains(self.driver)
     action.context_click(target).perform()
Esempio n. 5
0
    def test_layout_features(self):
        driver = self.driver
        driver.get(self.base_url)
        self.open_menu_section(4)

        # Test the title :
        new_title = 'The new title!'
        input_title = driver.find_element_by_id('title')
        input_title.clear()
        input_title.send_keys(new_title)
        title_svg = driver.find_element_by_css_selector(
            'g#map_title > text').text
        self.assertEqual(new_title, title_svg)

        # Test the graticule :
        driver.find_element_by_id('btn_graticule').click()
        time.sleep(0.2)
        if not self.try_element_present(By.ID, "Graticule"):
            self.fail("Graticule won't display")
        if not self.try_element_present(By.CSS_SELECTOR, "li.Graticule"):
            self.fail("Graticule won't appeat in layer manager")

        # Test the sphere element :
        driver.find_element_by_id('btn_sphere').click()
        time.sleep(0.2)
        if not self.try_element_present(By.ID, "Sphere"):
            self.fail("Sphere background won't display")
        if not self.try_element_present(By.CSS_SELECTOR, "li.Sphere"):
            self.fail("Sphere won't appeat in layer manager")

        # Test the text annotation and feed it with some text :
        driver.find_element_by_id('btn_text_annot').click()
        time.sleep(0.2)
        driver.find_element_by_id("svg_map").click()
        time.sleep(1)
        textarea_input = driver.find_element_by_id('annotation_content')
        time.sleep(0.25)
        textarea_input.clear()
        textarea_input.send_keys('Mon annotation de texte')
        driver.find_element_by_css_selector('.btn_ok').click()
        time.sleep(0.5)
        text_annot = driver.find_element_by_id('in_text_annotation_0')
        self.assertEqual(text_annot.is_displayed(), True)
        self.assertEqual(text_annot.text, 'Mon annotation de texte')
        self._verif_context_menu(text_annot, "text annotation")

        # Test the scale bar :
        driver.find_element_by_id('btn_scale').click()
        time.sleep(0.2)
        if not self.try_element_present(By.ID, "scale_bar"):
            self.fail("Scale bar won't display")
        self._verif_context_menu(
            driver.find_element_by_id("scale_bar"), "scale bar")
        self._verif_dbl_click_open_ctx_menu(
            driver.find_element_by_id("scale_bar"), "scale bar")

        # Test the north arrow :
        driver.find_element_by_id('btn_north').click()
        time.sleep(0.2)
        if not self.try_element_present(By.ID, "north_arrow"):
            self.fail("North arrow won't display")
        self._verif_context_menu(
            driver.find_element_by_id("north_arrow"), "north arrow")
        self._verif_dbl_click_open_ctx_menu(
            driver.find_element_by_id("north_arrow"), "north arrow")

        svg_map = driver.find_element_by_id("svg_map")

        # Test the arrow drawn by the user :
        driver.find_element_by_id('btn_arrow').click()
        time.sleep(0.2)
        driver.find_element_by_id("svg_map").click()
        time.sleep(0.1)
        # Move the cursor a bit in order to simulate the drawing of the arrow :
        ac = webdriver.ActionChains(driver)
        ac.move_to_element(svg_map).move_by_offset(10, 10).click().perform()
        driver.find_element_by_id("svg_map").click()
        time.sleep(1)
        if not self.try_element_present(By.ID, "arrow_0"):
            self.fail("User drawn arrow won't display")
        self._verif_context_menu(
            driver.find_element_by_id("arrow_0"), "user arrow")

        # Test the ellipse creation :
        driver.find_element_by_id('btn_ellipse').click()
        time.sleep(0.2)
        driver.find_element_by_id("svg_map").click()
        time.sleep(0.5)
        if not self.try_element_present(By.ID, "user_ellipse_0"):
            self.fail("Ellipse won't display")
        self._verif_context_menu(
            driver.find_element_by_id("user_ellipse_0"), "user ellipse")
Esempio n. 6
0
    def filterLocation(self):
        # Click add button
        advLeftRail = None
        advLeftRail = self.mDriver.find_element_by_id(tag_left_rail)
        if (None == advLeftRail):
            return False

        group_location = None
        group_location = advLeftRail.find_element_by_id(tag_location)
        if (None == group_location):
            return False

        btn_location = None
        btn_location = group_location.find_element_by_class_name(
            tag_facet_wrapper).find_element_by_class_name(
                tag_add_pills).find_element_by_class_name(tag_add_pills_btn)
        if (None == btn_location):
            return False

        btn_location.click()
        time.sleep(1)

        # Enter text form to trigger the hint
        advLeftRail = None
        advLeftRail = self.mDriver.find_element_by_id(tag_left_rail)
        if (None == advLeftRail):
            return False

        group_location = None
        group_location = advLeftRail.find_element_by_id(tag_location)
        if (None == group_location):
            return False

        form_location = None
        form_location = group_location.find_element_by_tag_name(tag_form)
        if (None == form_location):
            return False

        action = webdriver.ActionChains(self.mDriver)
        action.send_keys(txt_fill_location)
        action.perform()

        if (False == _waitLocationHintLoaded(self.mDriver, tag_left_rail,
                                             tag_location, tag_location_hint)):
            return False

        # Click the hint (send "TAB" key)
        advLeftRail = None
        advLeftRail = self.mDriver.find_element_by_id(tag_left_rail)
        if (None == advLeftRail):
            return False

        group_location = None
        group_location = advLeftRail.find_element_by_id(tag_location)
        if (None == group_location):
            return False

        form_location = None
        form_location = group_location.find_element_by_tag_name(tag_form)
        if (None == form_location):
            return False

        action = webdriver.ActionChains(self.mDriver)
        action.send_keys(Keys.TAB)
        action.perform()

        if (False == _waitLocationLabelLoaded(self.mDriver, tag_left_rail,
                                              tag_location,
                                              tag_location_label)):
            return False

        return True
chromedriver = '/usr/local/Cellar/chromedriver/chromedriver'
driver = webdriver.Chrome(chromedriver)
driver.get('https://news.v.daum.net/v/20210215132400800')

loop, count = True, 0

while loop and count < 10:
    try:
        element = WebDriverWait(driver, 5).until(
            EC.presence_of_element_located((
                By.CSS_SELECTOR,
                '#alex-area > div > div > div > div.cmt_box > div.alex_more > button'
            )))
        more_button = driver.find_element_by_css_selector(
            '#alex-area > div > div > div > div.cmt_box > div.alex_more > button'
        )
        webdriver.ActionChains(driver).click(more_button).perform()
        count += 1
        time.sleep(2)
    except TimeoutException:
        loop = False

comment_box = driver.find_element_by_class_name('list_comment')
comment_list = comment_box.find_elements_by_tag_name('li')
for num, comment_item in enumerate(comment_list):
    print(f"[{str(num)}]",
          comment_item.find_element_by_css_selector('div p').text)

driver.quit()
Esempio n. 8
0
    def SelectByOrder(cls, order):
        if order == "":
            return

        log.step_normal("Element [%s]: Do Select by Order [%s]" %
                        (cls.__name__, order))

        order = int(order)

        # cls.__wait()
        WebDriverWait(env.driver,
                      10).until(lambda the_driver: the_driver.find_element(
                          cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        # ul
        if elements[cls.index].tag_name == "ul":
            lis = elements[cls.index].find_elements_by_tag_name('li')

            if order > 0:
                # Wait and try more times if NO item found.
                t = 0
                while len(lis) == 0:
                    lis = elements[cls.index].find_elements_by_tag_name('li')
                    time.sleep(3)
                    t += 1
                    log.step_normal("Element [%s]: Wait 3 Seconds for [li]" %
                                    cls.__name__)

                    if t == 8 and len(lis) == 0:
                        log.step_fail("Element [%s]: List Count = [%s]." %
                                      (cls.__name__, len(lis)))
                        return

                log.step_normal("Element [%s]: List Count = [%s]." %
                                (cls.__name__, len(lis)))

                if order > len(lis):
                    log.step_normal("Element [%s]: Not so many lists. [%s]" %
                                    (cls.__name__, len(lis)))
                else:
                    log.step_normal("Element [%s]: Do Click [%s]" %
                                    (cls.__name__, order))
                    action = webdriver.ActionChains(env.driver)
                    action.click(lis[order - 1])
                    action.perform()
                    time.sleep(3)

            else:
                log.step_fail("Order = [%s], Value Error." % order)

        # select
        if elements[cls.index].tag_name == "select":
            options = elements[cls.index].find_elements_by_tag_name('option')

            if order > 0:
                # Wait and try more times if NO item found.
                t = 0
                while len(options) == 0:
                    options = elements[cls.index].find_elements_by_tag_name(
                        'option')
                    time.sleep(3)
                    t += 1
                    log.step_normal(
                        "Element [%s]: Wait 3 Seconds for [option]" %
                        cls.__name__)

                    if t == 8 and len(options) == 0:
                        log.step_fail("Element [%s]: options Count = [%s]." %
                                      (cls.__name__, len(options)))
                        return

                log.step_normal("Element [%s]: options Count = [%s]." %
                                (cls.__name__, len(options)))

                if order > len(options):
                    log.step_normal("Element [%s]: Not so many options. [%s]" %
                                    (cls.__name__, len(options)))
                else:
                    log.step_normal("Element [%s]: Do Click [%s]" %
                                    (cls.__name__, order))
                    action = webdriver.ActionChains(env.driver)
                    action.click(options[order - 1])
                    action.perform()
                    time.sleep(3)

            else:
                log.step_fail("Order = [%s], Value Error." % order)

        cls.__clearup()
Esempio n. 9
0
def calculate(to_single_iata):

    # driver = webdriver.Chrome(options=options, executable_path=r'C:\Users\Xarvis-PC\Desktop\chromedriver_win32\chromedriver.exe', service_args=args)
    driver = webdriver.Chrome(
        options=options,
        executable_path=
        r'C:\Users\Xarvis-PC\Desktop\chromedriver_win32\chromedriver.exe')

    def isvisible(attrib_type, locator, timeout=3):
        try:
            if attrib_type == 'ID':
                WebDriverWait(driver, timeout).until(
                    EC.visibility_of_element_located((By.ID, locator)))
            elif attrib_type == 'TAG_NAME':
                WebDriverWait(driver, timeout).until(
                    EC.visibility_of_element_located((By.TAG_NAME, locator)))
            elif attrib_type == 'CLASS_NAME':
                WebDriverWait(driver, timeout).until(
                    EC.visibility_of_element_located((By.CLASS_NAME, locator)))
            return True
        except TimeoutException:
            return False

    try:
        final_output = {}

        from_single_iata = list(from_IATA.keys())[0]
        url = 'https://www.happyeasygo.com/flights/' + from_single_iata + '-' + to_single_iata
        url_params = '?adults=' + str(adults) + '&cabinClass=' + cabinClass
        # print('url+url_params:', url+url_params)
        driver.get(url + url_params)
        time.sleep(10)
        # driver.refresh()
        driver.execute_script("location.reload(true);")

        if not isvisible('TAG_NAME', 'body', 5):
            return {}

        webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
        webdriver.ActionChains(driver).send_keys(Keys.HOME).perform()

        if round_trip:
            trip_type = from_IATA[from_single_iata] + '->' + to_IATA[
                to_single_iata] + '->' + from_IATA[from_single_iata]
        else:
            trip_type = from_IATA[from_single_iata] + '->' + to_IATA[
                to_single_iata]

        ld = {}

        def calender(id_name):

            if isvisible('ID', id_name, 10):
                el = driver.find_element_by_id(id_name)
                actions = webdriver.ActionChains(driver)
                try:
                    actions.move_to_element(el).click().perform()
                except ElementClickInterceptedException:
                    print('Issue:', driver.current_url)
                    return {}
                except:
                    print(222)
            else:
                print('Poor connection!')
                return {}

            #    print('Poor connectivity or unknown error at '+driver.current_url+' ... skipping')
            #    return {}

            # not working
            # el=driver.find_element_by_id(id_name)
            # driver.execute_script("arguments[0].click();", el)

            time.sleep(5)
            l = []
            # print('>>>', driver.current_url)
            # print('>>', len(driver.find_elements_by_class_name(r" ")))

            for c, e in enumerate(
                    driver.find_elements_by_xpath(
                        '//td[@data-handler="selectDay"]')):
                # print(c, e)

                try:
                    if e.get_attribute("title") != '':
                        # print('Airfare:', e.get_attribute("title"))
                        l.append(((datetime.now() +
                                   timedelta(days=c)).strftime("%Y%m%d"),
                                  int(float(e.get_attribute("title")))))
                except:
                    print('Airfare issue:', e.get_attribute("title"))
                    continue

                if c == scan_till_N_days:
                    break

            ld[trip_type] = l
            # print('ld:', ld)
            return ld

        try:
            depart = calender('D_date')[trip_type]
            if round_trip:
                arrival = calender('R_date')[trip_type]
        except KeyError:
            driver.quit()
            return

        d = {}
        total_price = 0

        # print('depart:', depart)
        # print('arrival:', arrival)

        if round_trip:
            for i in depart:
                if depart_on_weekend:
                    if datetime.strptime(i[0], "%Y%m%d").weekday() < 5:
                        continue
                for j in arrival:
                    if arrive_on_weekend:
                        if datetime.strptime(j[0], "%Y%m%d").weekday() < 5:
                            continue
                    total_price = (i[1] + j[1]) * adults
                    day_diff = (datetime.strptime(j[0], "%Y%m%d") -
                                datetime.strptime(i[0], "%Y%m%d")).days
                    # print('total_price:', total_price, day_diff, i[0], j[0])
                    if 0 <= day_diff <= maxGap and day_diff >= minGap and i[
                            0] <= j[0] and total_price <= maxINR:
                        d[i[0] + '-' + j[0]] = total_price
        else:
            for i in depart:
                if depart_on_weekend:
                    if datetime.strptime(i[0], "%Y%m%d").weekday() < 5:
                        continue
                total_price = (i[1]) * adults
                # print('total_price:', total_price)
                if total_price <= maxINR:
                    d[i[0]] = total_price

        # if len(d)>0:
        # print('d:', d)
        # print('Path '+trip_type+' available...')

        new_d = {}
        if d != {}:
            d = sorted(d.items(),
                       key=lambda item: item[1])[:cheapest_N_results]

            for date_strings, total_cached_price in d:
                cached_price = total_cached_price / adults
                from_str = datetime.strptime(
                    date_strings.split('-')[0], '%Y%m%d')

                if round_trip:
                    to_str = datetime.strptime(
                        date_strings.split('-')[1], '%Y%m%d')
                    new_url = url + '/' + from_str.strftime(
                        "%Y-%m-%d") + '-' + to_str.strftime(
                            "%Y-%m-%d") + url_params
                    key = (from_str.strftime("%d %B %Y (%A)") + ' to ' +
                           to_str.strftime("%d %B %Y (%A)"))
                else:
                    new_url = url + '/' + from_str.strftime(
                        "%Y-%m-%d") + url_params
                    key = from_str.strftime("%d %B %Y (%A)")

                # print('new_url:', new_url)
                try:
                    driver.get(new_url)
                    time.sleep(4)
                    driver.execute_script("location.reload(true);")
                    key = key + ' [' + driver.current_url + ']'

                    # print(driver.find_elements_by_class_name('fpr')[0])

                    # class_name = 'fpr'
                    class_name = 'fpr' if round_trip else 'price-origin'

                    if not isvisible('CLASS_NAME', class_name, 20):
                        print('Poor connection... at ' + new_url, class_name)
                        continue

                    new_price = driver.find_elements_by_class_name(
                        class_name)[0].text
                    new_price = eval((new_price.strip()).replace(',', ''))
                    value = new_price
                except:
                    driver.refresh()
                    time.sleep(4)
                    if not isvisible('CLASS_NAME', 'no-search-result', 10):
                        print('Poor connection.. at ' + new_url)
                        continue

                    ele = driver.find_element_by_id('no_result')

                    if ele.get_attribute("style").replace(
                            ' ', '').strip() != "display:none;":
                        print('No flight data-key:', key,
                              ele.get_attribute("style"))
                        continue
                    else:
                        key = key + ' (cached)'
                        value = cached_price

                if value * adults <= maxINR:
                    new_d[key] = value * adults

            new_d = sorted(new_d.items(), key=lambda item: item[1])
            # print('new_d:', trip_type, new_d)
            if new_d != []:
                final_output[trip_type] = new_d
        # driver.quit()
        return

    finally:
        if final_output != {}:
            pprint.pprint(final_output)
        driver.quit()
        return
Esempio n. 10
0
def indeed():
	IndeedId = worksheet.cell(1,6).value
	Indeedpwd = worksheet.cell(2,6).value
	companyName = worksheet.cell(5,6).value
	jobTitle = worksheet.cell(11,6).value
	location = worksheet.cell(10,6).value
	name = worksheet.cell(13,6).value
	phnno = str(int(worksheet.cell(20,6).value))
	typeofEmp = 2
	contractType = "5"
	salaryfrom = str(int(worksheet.cell(6,6).value))
	salaryto = str(int(worksheet.cell(7,6).value))
	jobDesc = worksheet.cell(24,6).value
	# ALL SITE PATHS 
	site_id = "https://secure.indeed.com/account/login"
	username = """//*[@id="login-email-input"]"""
	password = """//*[@id="login-password-input"]"""
	signInBtn = """//*[@id="login-submit-button"]"""
	validationMsgPath = """//*[@id="login-recaptcha-message-error"]"""
	postJobSite_id = "https://employers.indeed.com/p#post-job"
	companyNamePath = """//*[@id="JobCompanyName"]"""
	jobTitlePath = """//*[@id="JobTitle"]"""
	locationPath = """//*[@id="cityOrPostalCode"]"""
	namePath = """//*[@id="AdvertiserName"]"""
	phnnoPath = """//*[@id="AdvertiserPhoneNumber"]"""
	typeofEmpPath = """//*[@id="JobEmploymentType"]"""
	contractTypePath = """//*[@id="label-checkbox-option-""" + contractType + '"]'
	salaryfromPath = """//*[@id="JobSalary1"]"""
	salarytoPath = """//*[@id="JobSalary2"]"""
	jobDescPath = """//*[@id="AppendedJobDescription-editor-content"]"""
	employerAssistAgreePath = """//*[@id="plugin-smbcommunication-EmployerAssistLegalModal-modal_box_content"]/div/div/div/div/div[2]/div[2]/div[1]/button[1]"""
	removeBannerPath = """//*[@id="plugin-pie-AddCollaboratorsTheseusModal-modal_close_button"]"""
	escapeBodyPath = "/html/body"
	applicantQualificationsPath = """//*[@id="QualificationsVisibility"]/div[1]/div[2]/div/label/div[2]"""
	skillsAssessmentsPath = """//*[@id="SkillsAssessmentVisibility"]/div[1]/div[2]/div/label/div[2]"""
	ContinuePath = """//*[@id="sheet-next-button"]"""	
	driver.get(site_id)
	ele = driver.find_element_by_xpath(username).send_keys(IndeedId)
	driver.find_element_by_xpath(password).send_keys(Indeedpwd)
	driver.find_element_by_xpath(signInBtn).click()
	driver.implicitly_wait(2)
	driver.get(postJobSite_id)
	driver.implicitly_wait(2)
	driver.find_element_by_xpath(companyNamePath).clear()
	driver.find_element_by_xpath(companyNamePath).send_keys(companyName)
	driver.find_element_by_xpath(jobTitlePath).send_keys(jobTitle, Keys.DOWN, Keys.ENTER)
	driver.find_element_by_xpath(locationPath).send_keys(location, Keys.DOWN, Keys.ENTER)
	driver.find_element_by_xpath(ContinuePath).click()
	driver.implicitly_wait(4)
	try:
		driver.find_element_by_xpath(namePath).send_keys(name)
		driver.find_element_by_xpath(phnnoPath).send_keys(phnno, Keys.TAB)
		driver.find_element_by_xpath(ContinuePath).click()
	except:
		pass
	driver.implicitly_wait(4)
	for i in range(typeofEmp):
		driver.find_element_by_xpath(typeofEmpPath).send_keys(Keys.DOWN)
	driver.implicitly_wait(2)
	driver.find_element_by_xpath(contractTypePath).click()
	driver.find_element_by_xpath(salaryfromPath).send_keys(salaryfrom)
	driver.find_element_by_xpath(salarytoPath).send_keys(salaryto)
	driver.implicitly_wait(2)
	driver.find_element_by_xpath(jobDescPath).send_keys(jobDesc)
	driver.find_element_by_xpath(ContinuePath).click()
	driver.implicitly_wait(2)
	driver.find_element_by_xpath(employerAssistAgreePath).click()
	driver.implicitly_wait(2)
	try:
		driver.find_element_by_xpath(applicantQualificationsPath).click()
		driver.find_element_by_xpath(skillsAssessmentsPath).click()
	except:
		webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
	driver.implicitly_wait(1)
	driver.find_element_by_xpath(ContinuePath).click()
	driver.implicitly_wait(3)
	driver.find_element_by_xpath(ContinuePath).click()	
	print("Posted on indeed jobs")
	driver.implicitly_wait(4)
Esempio n. 11
0
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://www.w3schools.com")
driver.maximize_window()

button = driver.find_element_by_id('navbtn_references')

webdriver.ActionChains(driver).move_to_element(button).click(button).perform()
time.sleep(1)
driver.quit()
Esempio n. 12
0
 def __init__(self):
     self.driver = webdriver.Chrome(ChromeDriverManager().install())
     self.action = webdriver.ActionChains(self.driver)
Esempio n. 13
0
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        try:
            driver.find_element_by_css_selector(".mye4qd").click()
        except ElementNotInteractableException:
            break
    last_height = new_height

selem = driver.find_elements_by_css_selector('.rg_i.Q4LuWd')

if not os.path.exists("img"):
    os.mkdir("img")

for i, item in enumerate(selem):
    try:
        webdriver.ActionChains(
            driver=driver).move_to_element(item).click(item).perform()
        driver.implicitly_wait(2)
        img_url = driver.find_element_by_css_selector(
            '#Sva75c > div > div > div.pxAole > div.tvh9oe.BIB1wf > c-wiz > div > div.OUZ5W > div.zjoqD > div.qdnLaf.isv-id > div > a > img'
        ).get_attribute("src")
        urllib.request.urlretrieve(img_url, f"img/{filename}{i}.jpg")
        print(f"Downloaded Image {i}.")

    except NoSuchElementException as E:
        print("No Such Element :", E)
    except HTTPError as E:
        print("Http Error :", E)

driver.close()
 def createTrackLessonDocumentTag(self):
     print "Reading data from excel sheet"
     book=xlrd.open_workbook(os.path.join('TestData.xlsx'))
     first_sheet = book.sheet_by_name('CreateTag')
     print("Fetching the Attribute Name from Excel Sheet\n")
     # read a cell
     cell = first_sheet.cell(4,2)
     TagName = cell.value
     print TagName
     
     cell = first_sheet.cell(4,3)
     ExpectedSuccessMessage = cell.value
     print ExpectedSuccessMessage
     
     
     wait=WebDriverWait(driver, 60)
     wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]/a")))
     driver.find_element_by_xpath("html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]/a").click()
     print "Clicked on admin icon"
     wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]")))
     driver.find_element_by_xpath("html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]").click()
     print "Clicked on Admin"
     driver.find_element_by_xpath("html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]/div/ul/li[5]").click()
     print "Clicked on Tag"
     wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/header/h1")))
     print "Tag Page Loaded"
     driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/header/div/div/button").click()
     print "Clicked on Create Tag Button"
     wait.until(EC.visibility_of_element_located((By.ID,"add-tag-input")))
     print "Verifying Create Tag Name field "
     if driver.find_element_by_id("add-tag-input").is_displayed():
         print("Enter Tag name field is displayed")
     else:
         print ""
         raise Exception
     
     print "Verified Tag Name field"
     ele = driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div/div[1]/div/input")
     webdriver.ActionChains(driver).move_to_element(ele).send_keys(TagName).perform()
     print "Entered Tag Name :"+TagName
     time.sleep(6)
     driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div/div[2]/button[1]").click()
     time.sleep(6)
     wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div")))
     ActualMessage = driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div")
     ExpectedMessage =  TagName+ExpectedSuccessMessage
     print "ExpectedMessage "+ExpectedMessage
     print("Expected Success Message and Actual Success Message is Matching,Success Message Verified")
     print "Searching for the created Tag"
     wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[1]/div[2]/div/div/input")))
     time.sleep(6)
   
     element =driver.find_element_by_name("tag-index-search")
     element.send_keys(TagName)
     driver.find_element_by_name("tag-index-search").send_keys(Keys.ENTER)
     time.sleep(6)
     print "Entered Tag Name for Search"
     wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[2]/div/ul/li[1]")))
     print "Verifying the created Tag in the list"
     ele =driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[2]/div/ul/li[1]")
     print ele.text
     if driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[2]/div/ul/li[1]").is_displayed():
         print("Created Tag in the list")
     else:
         print ""
         raise Exception
Esempio n. 15
0
    # 找到移动按钮,找不到就跳出
    try:
        pic=chrome.find_element_by_xpath(
            '//div[@class="geetest_slider_button"]'
        )
        # if num>0:
        #     ref = chrome.find_element_by_xpath(
        #         '//a[@class="geetest_refresh_1"]'
        #     )
        #     webdriver.ActionChains(chrome).click(ref).perform()
    except:
        break
    sleep(2)
    # 截屏
    chrome.save_screenshot('screenshot.png')
    sleep(2)
    # 计算距离
    offset=pil.m()
    # 模拟轨迹,还是有问题,可以看到距离没问题,轨迹一直有问题
    newtrack=track.get_track(offset)
    webdriver.ActionChains(chrome).click_and_hold(pic).perform()
    for x in newtrack:
        webdriver.ActionChains(chrome).move_by_offset(xoffset=x,yoffset=random.randint(-5,5)).perform()
    sleep(0.5)
    # webdriver.ActionChains(chrome).move_by_offset(xoffset=offset, yoffset=0).perform()
    webdriver.ActionChains(chrome).release().perform()
    sleep(3)
    num+=1
sleep(5)
print()
def website_scrap_rtr(indict):
    #website_url is the url of the website with the 'page number' replace by '{}'
    #max_index is the integer index of the last page of the catalogue from the website
    #product_tuple_list is a list [product_tuple, ...] where product_tuples are all the possible [product_section, product_class]
    #img_tuple is a tuple [img_section, img_class]
    #title_tuple is a tuple [title_section, title_class]
    #price_tuple is a tuple [price_section, price_class]

    browser = webdriver.Chrome('C:/Users/Arno Murcia/Documents/chromedriver_win32/chromedriver.exe')
    browser.get("https://www.google.com")
    
    for i in range(1,indict['max_index']+1):                                                                        #Iterates through the pages of the website containing the catalogue from 1 to max_index
    #for i in range(1, 2):
        print('Scrapping page:',i)

        webdriver.ActionChains(browser).key_down(Keys.CONTROL).send_keys('t').key_up(Keys.CONTROL).perform()
        browser.get(indict['website_url'].format(i))
        soup = BeautifulSoup(browser.page_source, 'html.parser')

        #page = requests.get(indict['website_url'].format(i))
        #soup = BeautifulSoup(page.content, 'html.parser')
        products = soup.find_all(indict['catalogue_tuple'][0], class_=indict['catalogue_tuple'][1])
        all_products = []
        for p in products:
            all_products.append(p.find(indict['product_tuple'][0], class_= indict['product_tuple'][1]))

        #all_products = products.find_all(indict['product_tuple'][0], class_= indict['product_tuple'][1])        #get all products elements
        #print(all_products)

        global sku
        global title
        global description
        global details
        global designer
        global mrsp
        global currencyId
        global prices
        global variants
        global optionTypes
        global defaultImages

        element = 0
        
        for pc in all_products:
            element += 1
            print('Scraping product {} out of {}'.format(element, len(all_products)))
            
            detail_url = indict['website_prefix']+pc['href']
            #pc.find('a', attrs={'href': re.compile(indict['website_prefix'])}).get('href')         #website_prefix ="^https://www.lulus.com"

            webdriver.ActionChains(browser).key_down(Keys.CONTROL).send_keys('t').key_up(Keys.CONTROL).perform()
            #browser.find_element_by_id('body').send_keys(Keys.chord(Keys.CONTROL, 't'))
            browser.get(detail_url)

            python_first_button = browser.find_elements_by_class_name('mfp-close')
            if len(python_first_button)>0:
                python_first_button[0].click()


            rtr_details_buttons = browser.find_elements_by_class_name('collapsible-menu') #FHSU
            size = ""
            
            for b in rtr_details_buttons:
                b.click()
                #print('After click')
                b_detail = browser.find_element_by_class_name("active")
                #print(b_detail.text)
                
                if b_detail.find_element_by_class_name('summary-label').text == "STYLIST NOTES":
                    #print('in stylist')
                    text = b_detail.find_element_by_tag_name('p').text
                    #print(text)
                    description.append(text)                                    #Description Done
                if b_detail.find_element_by_class_name('summary-label').text == "SIZE & FIT":
                    #print('SF')
                    size = b_detail.find_element_by_tag_name('p').text
                    #print(text)
                if b_detail.find_element_by_class_name('summary-label').text == "PRODUCT DETAILS":
                    #print('PD')
                    text = b_detail.find_element_by_tag_name('p').text
                    details.append(text)                                        #Details Done
                    #print(text)
            
            #detail_page = requests.get(detail_url)
            #print("detail url:"+detail_url)
            detail_soup = BeautifulSoup(browser.page_source, 'html.parser')

            webdriver.ActionChains(browser).key_down(Keys.CONTROL).send_keys('w').key_up(Keys.CONTROL).perform()
            #browser.find_element_by_id('body').send_keys(Keys.chord(Keys.CONTROL, 'w'))
            #print(detail_soup.prettify())

            #all_variants = detail_soup.find_all(indict['variance_tuple'][0], class_= indict['variance_tuple'][1])
            pc_variants = []

            pc_images = []
            images = 4
            for img in detail_soup.find_all(indict['img_tuple'][0], class_= indict['img_tuple'][1]):
                if images >0:
                    images -= 1
                    pc_images.append(img.find('img')['src'])

            #pc_images = [img.find('img')['src'] for img in detail_soup.find_all(indict['img_tuple'][0], class_= indict['img_tuple'][1])]
            
            pc_variants.append({
                "id": 0,
                "options": {"sizes": size},
                "images": pc_images,
                "inStock": True})
##            for v in all_variants:
##                print("found variants")
##                variant_page = requests.get(re.compile(indict['website_prefix'], v.get('href')))
##                variant_soup = BeautifulSoup(detail_page.content, 'html.parser')
##                variants_img = [img.find('img')['src'] for img in detail_soup.find_all(indict['img_tuple'][0], class_= indict['img_tuple'][1])]
##                pc_variants.append({
##                    "id":variant_soup.find(indict['color_tuple'][0], class_indict['color_tuple'][1]),
##                    "options": {"color": detail_soup.find(indict['color_tuple'][0], class_indict['color_tuple'][1])},
##                    "images": variants_img,
##                    "inStock": True})
##                pc_images += variants_img

            sku.append(0)                                                                                          #SKU Done
            title.append(detail_soup.find(indict['title_tuple'][0], class_=indict['title_tuple'][1]).get_text())
            #description.append(detail_soup.find(indict['description_tuple'][0], class_= indict['description_tuple'][1]).get_text())
            #details.append(detail_soup.find(indict['details_tuple'][0], class_=indict['details_tuple'][1]))
            designer.append(detail_soup.find(indict['designer_tuple'][0], class_=indict['designer_tuple'][1]).get_text())
            #designer.append("Everlane")
            rprice = detail_soup.find(indict['price_tuple'][0], class_=indict['price_tuple'][1]).get_text()
            rprice.replace('–', 'to')
            mrsp.append(rprice)
            currencyId.append(indict['currencyId'])
            
            prices.append({"3": 0, "5": 0, "purchase": 0})
            
            variants.append(pc_variants)
##            print("sku Length: {}".format(len(sku)))
##            print("title Length: {}".format(len(title)))
##            print("description Length: {}".format(len(description)))
##            print("details Length: {}".format(len(details)))
##            print("designer Length: {}".format(len(designer)))
##            print("mrsp Length: {}".format(len(mrsp)))
##            print("currencyId Length: {}".format(len(currencyId)))
##            print("prices Length: {}".format(len(prices)))
##            print("variants Length: {}".format(len(variants)))
##            print("OptionType Length: {}".format(len(optionTypes)))
##            print("defaultImages Length: {}".format(len(defaultImages)))
            
            optionTypes.append([{"size": size}])
            defaultImages.append(pc_images)

            nImages = []
            for i in defaultImages:
                nImages.append(i)

        
    catalogue = pd.DataFrame({
        "sku": sku,
        "title": title,
        "description": description,
        "details": details,
        "designer": designer,
        "mrsp": mrsp,
        "currencyId": currencyId,
        "prices": prices,
        "variants": variants,
        "optionTypes": optionTypes,
        "defaultImages": nImages
        })

    return catalogue
Esempio n. 17
0
    def update_data(self, start_date=None, end_date=None):
        """Update consumption data"""
        daily_table = []
        monthly_table = []

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('whitelisted-ips')
        chrome_options.add_argument('headless')
        chrome_options.add_argument('no-sandbox')

        try:
            # Check selenuim connection
            r = requests.get(urljoin(self._selenium, 'wd/hub/status'))
            r.raise_for_status()

            with webdriver.Remote(
                    command_executor=urljoin(self._selenium, 'wd/hub'),
                    desired_capabilities=DesiredCapabilities.CHROME,
                    options=chrome_options) as driver:
                # Login
                # _LOGGER.debug('Login')
                driver.implicitly_wait(5)
                driver.get(self._host)
                driver.find_element_by_id('txtEmail').send_keys(self._username)
                driver.find_element_by_id('txtPassword').send_keys(
                    self._password)
                driver.find_element_by_id('btnLogin').click()
                # Extract some general data
                try:
                    element = driver.find_element_by_id('cphMain_lblMeterSN')
                    self._meter_number = element.text
                except NoSuchElementException:
                    pass
                try:
                    element = driver.find_element_by_id('spn_current_read')
                    self._last_read = element.text
                except NoSuchElementException:
                    pass
                try:
                    element = driver.find_element_by_id('spn_forecast')
                    self._forecast = element.text
                except NoSuchElementException:
                    pass
                try:
                    element = driver.find_element_by_id('spn_low_consumption')
                    self._low_consumption = element.text
                except NoSuchElementException:
                    pass
                try:
                    element = driver.find_element_by_id('spn_house_hold_avg')
                    self._house_hold_avg = element.text
                except NoSuchElementException:
                    pass
                try:
                    element = driver.find_element_by_id(
                        'cphMain_spn_messages_count')
                    self._messages_count = element.text
                except NoSuchElementException:
                    pass
                # Navigate to my consumption age
                driver.get(urljoin(self._host, 'Consumption.aspx#0'))
                try:
                    WebDriverWait(driver, 5).until(
                        EC.presence_of_element_located((By.ID, 'Consumption')))
                except TimeoutException:
                    _LOGGER.error(
                        'Loading of my consumption page took too much time')
                    driver.close()
                    return False
                # _LOGGER.debug(f"{driver.current_url}")
                # Switch to daily table view
                element = driver.find_element_by_id('btn_table')
                webdriver.ActionChains(driver).move_to_element(element).click(
                    element).perform()
                try:
                    WebDriverWait(driver, 5).until(
                        EC.presence_of_element_located(
                            (By.CLASS_NAME, 'AlertsTable')))
                except TimeoutException:
                    _LOGGER.error('Loading of table took too much time')
                    driver.close()
                    return False
                # _LOGGER.debug(f"{driver.current_url}")
                html = driver.page_source
                # Extract daily table
                if html:
                    soup = BeautifulSoup(html, features="html.parser")
                    table = soup.find('table', attrs={'class': 'AlertsTable'})
                    if table:
                        for row in table.find('tbody').find_all('tr'):
                            cols = row.find_all('td')
                            cols = [ele.text.strip() for ele in cols]
                            if len(cols):
                                daily_table.append(
                                    [ele for ele in cols if ele])
                        # Remove table summary
                        if len(daily_table):
                            daily_table.pop()
                # Switch to monthly
                element = driver.find_element_by_id('btn_period_type_0')
                webdriver.ActionChains(driver).move_to_element(element).click(
                    element).perform()
                time.sleep(1)
                # _LOGGER.debug(f"{driver.current_url}")
                html = driver.page_source
                # Extract daily table
                if html:
                    soup = BeautifulSoup(html, features="html.parser")
                    table = soup.find('table', attrs={'class': 'AlertsTable'})
                    if table:
                        for row in table.find('tbody').find_all('tr'):
                            cols = row.find_all('td')
                            cols = [ele.text.strip() for ele in cols]
                            if len(cols):
                                monthly_table.append(
                                    [ele for ele in cols if ele])
                        # Remove table summary
                        if len(monthly_table):
                            monthly_table.pop()
                # Update new values
                self._daily_table = daily_table
                self._monthly_table = monthly_table
                driver.close()
        except WebDriverException:
            _LOGGER.error('Webdriver error')
        except requests.exceptions.HTTPError as errh:
            _LOGGER.error('Sellenuim http error: %s', errh)
        except requests.exceptions.ConnectionError as errc:
            _LOGGER.error('Sellenuim error connecting: %s', errc)
        except requests.exceptions.Timeout as errt:
            _LOGGER.error("Sellenuim timeout error: %s", errt)
        except requests.exceptions.RequestException as err:
            _LOGGER.error("OOps: error: %s", err)

        return True
Esempio n. 18
0
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')


dr= webdriver.Chrome()
file_path = 'file:///' + os.path.abspath('level_locate.html')
dr.get(file_path)

#点击Link1链接(弹出下拉列表)
dr.find_element_by_link_text('Link1').click()

#找到id为dropdown1的父元素
WebDriverWait(dr,10).until(lambda the_driver: the_driver.find_element_by_id('dropdown1').is_displayed())

#在父元素下找到link为Action的子元素
menu= dr.find_element_by_id('dropdown1').find_element_by_link_text('Action')

#鼠标移动到子元素上
webdriver.ActionChains(dr).move_to_element(menu).perform()

sleep(3)

dr.quit()



Esempio n. 19
0
    def filterCurrentCompany(self, company_name):
        # Click add button
        advLeftRail = None
        advLeftRail = self.mDriver.find_element_by_id(tag_left_rail)
        if (None == advLeftRail):
            return False

        group_keywords = None
        group_keywords = advLeftRail.find_element_by_id(tag_current_company)
        if (None == group_keywords):
            return False

        btn_keywords = None
        btn_keywords = group_keywords.find_element_by_class_name(
            tag_facet_wrapper).find_element_by_class_name(
                tag_add_pills).find_element_by_class_name(tag_add_pills_btn)
        if (None == btn_keywords):
            return False

        btn_keywords.click()
        time.sleep(1)

        # Enter text form to trigger the hint
        advLeftRail = None
        advLeftRail = self.mDriver.find_element_by_id(tag_left_rail)
        if (None == advLeftRail):
            return False

        group_location = None
        group_location = advLeftRail.find_element_by_id(tag_current_company)
        if (None == group_location):
            return False

        form_location = None
        form_location = group_location.find_element_by_tag_name(tag_form)
        if (None == form_location):
            return False

        action = webdriver.ActionChains(self.mDriver)
        action.send_keys(company_name)
        action.perform()

        if (False == _waitLocationHintLoaded(self.mDriver, tag_left_rail,
                                             tag_current_company,
                                             tag_current_company_hint)):
            #print("Something wrong happened with company" + company_name + ", You can input manually")
            #time.sleep(1)
            return False

        # Click the hint (send "Arrown Down" key and "Enter" key)
        advLeftRail = None
        advLeftRail = self.mDriver.find_element_by_id(tag_left_rail)
        if (None == advLeftRail):
            return False

        group_location = None
        group_location = advLeftRail.find_element_by_id(tag_current_company)
        if (None == group_location):
            return False

        form_location = None
        form_location = group_location.find_element_by_tag_name(tag_form)
        if (None == form_location):
            return False

        action = webdriver.ActionChains(self.mDriver)
        action.send_keys(Keys.ARROW_DOWN + Keys.ENTER)
        action.perform()

        if (False == _waitLocationLabelLoaded(self.mDriver, tag_left_rail,
                                              tag_current_company,
                                              tag_current_company_label)):
            #print("Something wrong happened with company: " + company_name + ", You can input manually")
            #time.sleep(1)
            return False

        return True
Esempio n. 20
0
def teamMemberLoginSelectLeader(email, num_start, num_end, password, env):
    # open new browser and login via
    # browser = webdriver.Chrome()
    for memberNum in range(num_start, num_end):
        # browser = webdriver.Chrome()
        print(email, ", team number = %s" % memberNum)
        randUser = email.split('@')[0]
        teamMemberEmail = "%s-%s@%s" % (randUser, memberNum,
                                        mailservice_domain)
        # browser.get("https://weeklyreport.qa.entreleadership.com/sign-in")
        time.sleep(1)
        # Sign out of Owner Account
        browser.get("https://weeklyreport.%s.entreleadership.com/sign-out" %
                    env)
        #  sign in to WRT
        loginWeeklyReport('https://weeklyreport.%s.entreleadership.com' % env,
                          teamMemberEmail, 'password')
        browser.implicitly_wait(20)
        time.sleep(2)

        # Select a leader
        browser.find_element_by_xpath(
            "//div[@style='cursor: pointer; height: 100%; position: relative; width: 100%;']"
        ).click()
        time.sleep(2)
        cleanRandUser = randUser.replace('-', '')
        cleanRandUser = cleanRandUser.replace('+', '')
        if memberNum == 0:
            browser.find_element_by_xpath("//span[@name='testFirstName %s']" %
                                          cleanRandUser).click()
        elif memberNum == 1:
            browser.find_element_by_xpath("//span[@name='fName %s-0']" %
                                          randUser).click()
        elif memberNum == 2:
            browser.find_element_by_xpath("//span[@name='fName %s-1']" %
                                          randUser).click()
            time.sleep(0.5)
            browser.find_element_by_xpath("//span[@name='fName %s-0']" %
                                          randUser).click()
        elif memberNum == 3:
            browser.find_element_by_xpath("//span[@name='fName %s-1']" %
                                          randUser).click()
            time.sleep(0.5)
            browser.find_element_by_xpath("//span[@name='fName %s-0']" %
                                          randUser).click()
        elif memberNum > 3:
            browser.find_element_by_xpath("//span[@name='fName %s-1']" %
                                          randUser).click()

        time.sleep(2)
        webdriver.ActionChains(browser).send_keys(Keys.ESCAPE).perform()
        print("after pressing the escape key")
        time.sleep(2)
        browser.find_element_by_xpath(
            "//button[contains(text(), 'Continue')]").click()
        browser.implicitly_wait(15)
        time.sleep(6)
        # fill out WRT weekly form Previous Week
        print("signing out")
        browser.find_element_by_xpath(
            "//a[contains(text(), 'sign out')]").click()
        browser.implicitly_wait(15)
        time.sleep(5)
        print("logging back in")
        loginWeeklyReport('https://weeklyreport.%s.entreleadership.com' % env,
                          teamMemberEmail, 'password')
        time.sleep(4)
        completeWRTform('previousWeek', memberNum, teamMemberEmail, env)
        # browser.get("https://weeklyreport.qa.entreleadership.com")
        completeWRTform('currentWeek', memberNum, teamMemberEmail, env)
Esempio n. 21
0
 def run(self):
     id,generate_url, course_id, class_room_id, user_name, user_id, user_mobile, play_time = self.rs
     try:
         driver = self.__startChrome()
         driver.maximize_window()
         driver.get(generate_url)
         driver.implicitly_wait(10)
         time.sleep(100000)
         #选择需要播放的视频
         but_a_xpath = "//div[@class='neirong']//a[@href='javascript:toWatch(%s,%s);'][@class='but_a']" % (course_id, class_room_id) if self.is_live \
             else "//div[@class='neirong']//a[@href='javascript:toReview(%s,%s);'][@class='but_a']" %(course_id,class_room_id)
         WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath(but_a_xpath).is_displayed())
         but_a = driver.find_element_by_xpath(but_a_xpath)
         #元素滚动到最顶端
         driver.execute_script("arguments[0].scrollIntoView(true);",but_a)
         webdriver.ActionChains(driver).move_to_element(but_a).perform()
         but_a.click()
         if self.is_live: #直播
             #监听是否已开始播放了
             sys_info_xpath = '//div[@class="system_info de"]'
             wait_start_time = time.time()
             while True:
                 try:
                     WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath(sys_info_xpath).is_displayed())
                     sys_info = driver.find_element_by_xpath(sys_info_xpath)
                     if sys_info.get_attribute('style') == 'display: block; top: 0px;':
                         logger.info(u'%s-%s,直播已经开始播放了哦', user_name, user_mobile)
                         break
                     else:
                         logger.info(u'%s-%s,直播并没有播放了哦', user_name, user_mobile)
                 except  Exception:
                     pass
                 if time.time() - wait_start_time > WAIT_DOWNLOAD_MAX_TIME:
                     raise Exception(u'等待“直播”播放时间超时,超过了最大等待下载时间 %d s' % WAIT_DOWNLOAD_MAX_TIME)
             # 监听实际播放时长哦
             live_play_time = random.randint(self.min_live_play_time,self.max_live_play_time)   #随机获取播放时间
             start_time = time.time()
             real_play_time = time.time() - start_time
             # 防止睡眠时间太长无法唤醒
             while real_play_time < live_play_time:
                 time.sleep(5)
                 real_play_time = time.time() - start_time
             logger.info(u'%s-%s,播放结束哦了!目标播放时间:%d s,实际播放时间: %d s', user_name, user_mobile, live_play_time, real_play_time)
         else:
             #查看是否在播放中
             playBtn_xpath = "//a[@id='playBtn']"
             time.sleep(100)
             WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath(playBtn_xpath).is_displayed())
             playBtn = driver.find_element_by_xpath(playBtn_xpath)
             webdriver.ActionChains(driver).move_to_element(playBtn).perform()
             isNotPlay = True
             #开始等待的下载时间
             wait_start_time=time.time()
             while isNotPlay:
                 logger.info(u'%s-%s,等待下载中...%s',user_name,user_mobile,playBtn.get_attribute('class'))
                 isNotPlay =  "play_btn gs-icon-pause" != playBtn.get_attribute('class')
                 if time.time() - wait_start_time > WAIT_DOWNLOAD_MAX_TIME:
                     raise Exception(u'等待播放时间超时,超过了最大等待下载时间 %d s'% WAIT_DOWNLOAD_MAX_TIME)
                 time.sleep(2)
             #监听实际播放时长哦
             start_time = time.time()
             logger.info(u'%s-%s,开始播放了哦',user_name,user_mobile)
             real_play_time = time.time() - start_time
             #防止睡眠时间太长无法唤醒
             while real_play_time < play_time:
                 time.sleep(5)
                 real_play_time = time.time()-start_time
             logger.info(u'%s-%s,播放结束哦了!目标播放时间:%d s,实际播放时间: %d s',user_name,user_mobile,play_time,real_play_time)
         mysql = Mysql()
         try:
             sql = "update t_hzb_course set state=%s,real_play_time=%s,modify_time=now(),client_phone=%s,play_type=%s WHERE id=%s and user_id=%s"
             mysql.execute(sql,(2,real_play_time,self.CLIENT_PHONE,1 if self.is_live else 0,id,user_id))
             mysql.commit()
         except Exception:
             mysql.rollback()
             logger.exception(u'观看视频完成更新时异常')
         finally:
             mysql.close()
     except Exception as e:
         global fail_total
         fail_total += 1
         logger.exception(u'视频播放出现问题!,异常信息:%s',e.message)
     finally:
         self.__closeChrome(driver)
Esempio n. 22
0
	def navigate_car_page(self, page_name):
		menu = self.find_element(u'车辆', self.Link_Text)
		webdriver.ActionChains(self.my_driver).move_to_element(menu).perform()
		WebDriverWait(self.my_driver, 3).until(lambda d: d.find_element_by_link_text(page_name).is_displayed())
		self.find_element(page_name, self.Link_Text).click()
		WebDriverWait(self.my_driver, 3).until(lambda d: d.find_element_by_class_name('tab_list_nowOrder').is_displayed())
Esempio n. 23
0
 def make_double_click(self, target):
     action = webdriver.ActionChains(self.driver)
     action.double_click(target).perform()
Esempio n. 24
0
def accept_code(gid, gpass, gurl):
    ################### webdriver config ############
    useragent = {
        "original_fi":
        "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
        "original_ch":
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
        "firefox_android":
        "Mozilla/5.0 (Android 9; Mobile; rv:68.0) Gecko/68.0 Firefox/68.0",
        "ch_s20":
        "Mozilla/5.0 (Linux; Android 10; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Mobile Safari/537.36",
        "ch_note10p":
        "Mozilla/5.0 (Linux; Android 9; SM-N976V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.89 Mobile Safari/537.36",
        "ch_s10":
        "Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-G977N Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/9.2 Chrome/67.0.3396.87 Mobile Safari/537.36",
        "focus":
        "Mozilla/5.0 (Linux; Android 9) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Focus/4.7.1 Chrome/75.0.3770.143 Mobile Safari/537.36",
        "ubuntu":
        "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/88.0",
        "win_firefox":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0",
        "win_chrome":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
        "ff2mobile":
        "Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/88.0"
    }
    #options = webdriver.ChromeOptions()
    # options.add_argument("start-maximized")
    # options.add_argument("--disable-dev-shm-usage")
    # options.add_argument('--disable-extensions')
    # options.add_argument('--disable-blink-features')
    # options.add_argument('--profile-directory=Default')
    # options.add_argument("--incognito")
    # options.add_argument("--disable-plugins-discovery");
    # options.add_argument("--start-maximized")
    # options.add_argument("--disable-blink-features=AutomationControlled")
    # options.add_argument("--disable-infobars")
    # options.add_argument("--remote-debugging-port=9222");
    #options.add_experimental_option("excludeSwitches", ["enable-automation"])
    #options.add_experimental_option('useAutomationExtension', False)
    #driver = webdriver.Chrome(options=options)
    # #### options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); #####
    #driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": useragent["original_ch"] })
    #driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
    profile = webdriver.FirefoxProfile()
    options = webdriver.FirefoxOptions()
    #options.add_argument("--headless")
    profile.set_preference("dom.webdriver.enabled", False)
    profile.set_preference('useAutomationExtension', False)
    profile.set_preference("general.useragent.override",
                           useragent["ff2mobile"])
    profile.update_preferences()
    desired = DesiredCapabilities.FIREFOX
    driver = webdriver.Firefox(firefox_profile=profile,
                               options=options,
                               desired_capabilities=desired)
    actions = webdriver.ActionChains(driver)
    print(driver.execute_script("return navigator.userAgent;"))
    #####################################################################
    authurl = 'https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.com'
    user = gid
    passw = gpass
    driver.get(authurl)
    time.sleep(10 * slow_motion)
    driver.implicitly_wait(10)
    driver.find_element(By.ID, "identifierId").send_keys(user)
    driver.find_element(By.ID, "identifierId").send_keys(Keys.ENTER)
    time.sleep(3.6 * slow_motion)
    driver.implicitly_wait(10)
    time.sleep(0.1 * slow_motion)
    driver.find_element(By.NAME, "password").send_keys(passw)
    driver.find_element(By.NAME, "password").send_keys(Keys.ENTER)
    driver.implicitly_wait(10)
    time.sleep(5 * slow_motion)
    #driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
    driver.get(gurl)
    time.sleep(7 * slow_motion)
    driver.implicitly_wait(10)
    print('########### accept_code ############')
    try:
        Acchoose = driver.find_element(By.CSS_SELECTOR, "ul li div div")
        print(Acchoose)
        Acchoose.click()
    finally:
        time.sleep(1.3 * slow_motion)
        driver.implicitly_wait(10)
    driver.find_element(By.ID, "submit_approve_access").click()
    time.sleep(2.3 * slow_motion)
    driver.implicitly_wait(10)
    KeyDriver = driver.find_element(By.CSS_SELECTOR, "textarea")
    gkey = KeyDriver.text
    print(gkey)
    time.sleep(5 * slow_motion)

    driver.close()
    try:
        cmd2 = 'kill -9 $(ps -x | grep firefox)'
        results = subprocess.run(cmd2,
                                 shell=True,
                                 check=True,
                                 executable='/bin/bash')
    except:
        print('error firefox closing')
    return gkey
Esempio n. 25
0
 def submit(self):
     webdriver.ActionChains(self.chrome).send_keys(Keys.CONTROL,
                                                   Keys.RETURN,
                                                   Keys.CONTROL).perform()
Esempio n. 26
0
# Import required packages
from selenium import webdriver
from time import sleep

browser = webdriver.Firefox()    # setup web-browser
browser.get('http://google.com')  # set URL
inputs = browser.find_elements_by_css_selector('form input')  # find input field

for i in inputs:           # loop through inout
    if i.is_displayed():   # check whether displayed or not
        search_bar = i     # set search bar field
        break              # exit from loop

search_bar.send_keys('web scraping with python')   # send key for selected field
search_bar.submit()  # submit the page now

browser.implicitly_wait(10)  # wait for some time
results = browser.find_elements_by_css_selector('div.bkWMgd h2')  # select result

print(results)  # print result

for r in results:  # loop through result
    browser.execute_script("arguments[0].scrollIntoView({behavior: 'smooth'});", r)
    action = webdriver.ActionChains(browser)  # setup field to formulate actions
    action.move_to_element(r)  # Ask browser to move to specified result
    action.perform()  # Now ask to perform the operation
    sleep(2)  # go to sleep for some time

browser.quit()  # close browser now
print("Done processing result page")  # print final message
Esempio n. 27
0
    def ban(self, nickname: str):
        try:
            print("Starting to ban {0}".format(nickname))

            desired_cap = {
                'os': 'Windows',
                'os_version': '10',
                'browser': 'firefox',
                'browser_version': '32.0'
            }

            driver = webdriver.Remote(
                command_executor=
                'http://*****:*****@hub.browserstack.com:80/wd/hub',
                desired_capabilities=desired_cap)

            driver.maximize_window()

            tuple = self._find_tuple(nickname)
            driver.get("{0}{1}-{2}".format(Banner.URL, *tuple))

            email = driver.find_element_by_css_selector('#email')
            password = driver.find_element_by_css_selector('#password')
            button = driver.find_element_by_css_selector('#signin_btn')

            email.send_keys(Banner.LOGIN)
            password.send_keys(Banner.PASSWORD)

            button.click()

            print("Entering an email and a password...")

            search = WebDriverWait(driver, 15).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, '.member_filter')))

            search.send_keys(nickname, Keys.ENTER)
            print("Searching...")
            time.sleep(2)

            pop_up = WebDriverWait(driver, 5).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, '.admin_list_item')))
            pop_up.click()

            print("Pop-up...")
            #time.sleep(2)

            disable = WebDriverWait(driver, 5).until(
                EC.visibility_of_element_located(
                    (By.CSS_SELECTOR, '.api_disable_account')))

            print("Enabled: %s" % disable.is_enabled())
            print("Displayed: %s" % disable.is_displayed())

            actions = webdriver.ActionChains(driver)
            actions.move_to_element(disable)
            actions.click(disable)
            actions.perform()

            time.sleep(3)
            print("{0} was banned!".format(nickname))

            return True
        except Exception as exc:
            print("Error during banning: {0}".format(exc))
            return False
        finally:
            driver.quit()
Esempio n. 28
0
 def move_mouse(self, locator):
     webdriver.ActionChains(self._driver).move_to_element(locator).perform()
Esempio n. 29
0
 for line in d_lines:
     if current_space not in line:
         if line.strip():
             coun = random.choice(countries)
             print(coun)
             print(line)
             chrome_options = Options()
             chrome_options.add_experimental_option("detach", True)
             chrome_options.add_extension('8.0.4.0_0.crx')
             chrome_options.add_extension('4.1.2_0.crx')
             driver = webdriver.Chrome(options=chrome_options)
             driver.maximize_window()
             wait = WebDriverWait(driver, 3)
             presence = EC.presence_of_element_located
             visible = EC.visibility_of_element_located
             actions = webdriver.ActionChains(driver)
             print(driver.command_executor._url)
             print(driver.session_id)
             time.sleep(1)
             driver.get(
                 "https://account.zenmate.com/en_US/login?redirectTo=/en_US/devices"
             )
             driver.minimize_window()
             driver.maximize_window()
             driver.minimize_window()
             driver.maximize_window()
             time.sleep(1)
             curr = driver.current_window_handle
             for handle in driver.window_handles:
                 driver.switch_to.window(handle)
                 if handle != curr:
    def scrape(self):
        ''' 
        Search for the words in the words_data.txt file.
        '''
        data_json = []
        data = []
        if len(self.key) == 0:  # If no key is entered, config.json is used.
            f = open(self.determine_path() + '/config/words_data.txt',
                     "r")  # Open config.json
            mess_list = f.readlines()
            f.close()
        else:  # If a key is entered.
            if (type(self.key) == str):  # If the key is a single string value.
                mess_list = [self.key]
            elif (type(self.key) == list):  # If the key is a list.
                mess_list = self.key

        for mess in mess_list:
            mess = re.sub('\n', '', mess)  # Remove '\n'.
            try:
                exit_search = self.driver.find_element_by_class_name(
                    'iconContainer-O4O2CN'
                )  # Find the exit button of a pop up.
                exit_search.location_once_scrolled_into_view  # Scroll into view.
                exit_search.click()  # Click on the exit button.
            except:
                pass

            search_word = self.driver.find_element_by_class_name(
                'public-DraftEditor-content')  # Find the search box.
            search_word.click()  # Click on the search box.
            time.sleep(1)
            search_word.send_keys(mess)  # Type the key.
            webdriver.ActionChains(self.driver).send_keys(
                Keys.ENTER).perform()  # Press ENTER.
            time.sleep(5)

            today_date = dt.today().strftime("%d/%m/%Y")  # Get today's date.
            yesterday_date = (dt.today() - timedelta(days=1)).strftime(
                "%d/%m/%Y")  # Get yesterday's date.

            while (1):
                page = soup(self.driver.page_source,
                            'html.parser')  # Get the html code.
                search_result = page.find_all(
                    "div",
                    class_="hit-1fVM9e")  # Get the result of the search.
                if (len(search_result) > 0):  # If there is a match.
                    for i in tqdm(range(len(search_result))):
                        dates = search_result[i].find_all(
                            "span", class_="timestamp-3ZCmNB")  # Get the date.
                        tt = self.clean_html(str(dates[0]))  # Clean the date.

                        if ("Aujourd’hui" in tt):
                            tt = dt.strptime(today_date, "%d/%m/%Y")
                        elif ("Hier" in tt):
                            tt = dt.strptime(yesterday_date, "%d/%m/%Y")
                        else:
                            tt = dt.strptime(tt, "%d/%m/%Y")

                        print(tt)

                        if (
                            (tt >= self.start_date) and (tt <= self.end_date)
                        ):  # If the search results date is between the start date and the end date.
                            if self.context:
                                _name = self.extract_names(
                                    str(search_result[i].find(
                                        "div", class_="username-1A8OIy")))
                                _image = self.extract_image(
                                    str(search_result[i].find(
                                        "img", class_="threads-avatar-hack")))
                                _time = str(tt)  # Get the date.
                                _message = self.extract_message(
                                    str(search_result[i].find(
                                        "div",
                                        class_="messageContent-2qWWxC")))
                                context_data = [_name, _image, _time, _message]

                                container = self.driver.find_elements_by_class_name(
                                    "jumpButton-JkYoYK"
                                )[i]  # html container that we want to get rid of.
                                self.driver.execute_script(
                                    "arguments[0].style.display = 'inline';",
                                    container
                                )  # Change its css display to none.

                                jump_word = self.driver.find_elements_by_class_name(
                                    'jumpButton-JkYoYK'
                                )[i]  # find the jump button to open the conversation.
                                self.driver.execute_script(
                                    "return arguments[0].scrollIntoView(true);",
                                    jump_word)  # Scroll into view.
                                jump_word.click()  # Click on the jump button
                                time.sleep(2)
                                scrape_message = ScrapeMessages.ScrapeMessages(
                                    self.driver, context_data,
                                    self.json_parser, self.start_date,
                                    self.end_date,
                                    self.room_name)  # Scrape the conversation.
                                if (self.json_parser):
                                    scrape_message.scrape()
                                else:
                                    data_json.append(scrape_message.scrape())
                            else:
                                _name = self.extract_names(
                                    str(search_result[i].find(
                                        "div", class_="username-1A8OIy")))
                                _image = self.extract_image(
                                    str(search_result[i].find(
                                        "img", class_="threads-avatar-hack")))
                                _time = str(tt)  # Get the date.
                                _message = self.extract_message(
                                    str(search_result[i].find(
                                        "div",
                                        class_="messageContent-2qWWxC")))
                                data.append([_name, _image, _time, _message])

                    if (
                            tt < self.start_date
                    ):  # If a search result got a date < start_date then we start searching for the next key.
                        break

                    try:
                        next_page = self.driver.find_elements_by_class_name(
                            'paginationButton-3u4jo8')[
                                1]  # Find the next button.
                        next_page.location_once_scrolled_into_view  # Scroll into view.
                        next_page.click()  # Click on the nex button.
                        time.sleep(5)

                    except:  # if there are no more pages, we start searching for the next key.
                        break
                else:  # If there is no match, we start searching for the next key.
                    break

        if (not self.json_parser):
            if self.context:
                return data_json
            else:
                data_json_full = []
                data_json = {}
                for i in range(len(data)):
                    data_json['name'] = data[i][0]
                    data_json['image'] = data[i][1]
                    data_json['time'] = data[i][2]
                    data_json['message'] = data[i][3]
                    data_json_full.append(data_json)
                    data_json = {}
                return data_json_full
        else:
            if (not self.context):
                data_json_full = []
                data_json = {}
                for i in range(len(data)):
                    data_json['name'] = data[i][0]
                    data_json['image'] = data[i][1]
                    data_json['time'] = data[i][2]
                    data_json['message'] = data[i][3]
                    data_json_full.append(data_json)
                    data_json = {}

                with open('data_no_context.json', 'w') as outfile:
                    json.dump(data_json_full, outfile)