Ejemplo n.º 1
0
    def parse(self, response):
        self.driver.get(response.url)

        while True:
            time.sleep(1)
            try:
                WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, '//p[@class="propertyName"]/a')))
            except TimeoutException:
                return
            resp = TextResponse(url=self.driver.current_url, body=self.driver.page_source, encoding='utf-8')
            urls = resp.xpath('//p[@class="propertyName"]/a/@href').extract()
            pprint(urls)
            #urls=['http://www.magicbricks.com/propertyDetails/270-Sq-ft-Studio-Apartment-FOR-Sale-Vatika-City-in-Gurgaon&id=4d423230333337333839?from=search']
            if len(urls) == 0:
                return
            for url in urls:
                abs_url = 'http://www.squareyards.com' + url
                yield scrapy.Request(abs_url, callback=self.parse_property_info)

            try :
                link = self.driver.find_element_by_xpath('//ul[@class="newpagination"]/li[2]')
                actions = ActionChains(self.driver)
                actions.click(link)
                actions.perform()
            except:
                return
Ejemplo n.º 2
0
    def testSelectingMultipleItems(self, driver, pages):
        """Copied from org.openqa.selenium.interactions.CombinedInputActionsTest."""
        pages.load("selectableItems.html")
        if driver.capabilities["browserName"] == "phantomjs":
            pytest.xfail("phantomjs driver does not seem to select all the elements")
        reportingElement = driver.find_element_by_id("infodiv")
        assert "no info" == reportingElement.text

        listItems = driver.find_elements_by_tag_name("li")
        selectThreeItems = (
            ActionChains(driver)
            .key_down(Keys.CONTROL)
            .click(listItems[1])
            .click(listItems[3])
            .click(listItems[5])
            .key_up(Keys.CONTROL)
        )
        selectThreeItems.perform()

        assert "#item2 #item4 #item6" == reportingElement.text

        # Now click on another element, make sure that's the only one selected.
        actionsBuilder = ActionChains(driver)
        actionsBuilder.click(listItems[6]).perform()
        assert "#item7" == reportingElement.text
Ejemplo n.º 3
0
    def testSelectingMultipleItems(self, driver, pages):
        """Copied from org.openqa.selenium.interactions.CombinedInputActionsTest."""
        if driver.capabilities['browserName'] == 'firefox':
            pytest.skip("Actions not available in Marionette. https://bugzilla.mozilla.org/show_bug.cgi?id=1292178")
        if driver.capabilities['browserName'] == 'phantomjs':
            pytest.xfail("phantomjs driver does not seem to select all the elements")

        pages.load("selectableItems.html")
        reportingElement = driver.find_element_by_id("infodiv")
        assert "no info" == reportingElement.text

        listItems = driver.find_elements_by_tag_name("li")
        selectThreeItems = ActionChains(driver) \
            .key_down(Keys.CONTROL) \
            .click(listItems[1]) \
            .click(listItems[3]) \
            .click(listItems[5]) \
            .key_up(Keys.CONTROL)
        selectThreeItems.perform()

        assert "#item2 #item4 #item6" == reportingElement.text

        # Now click on another element, make sure that's the only one selected.
        actionsBuilder = ActionChains(driver)
        actionsBuilder.click(listItems[6]).perform()
        assert "#item7" == reportingElement.text
Ejemplo n.º 4
0
    def goToMatsPerformQuery(self):
        # Try to find "Return to search page" link.
        t = g_bd.d.find_elements_by_link_text('Return')
        if len(t) > 0:
            self.focusActiveElement()
            t[0].click()
            time.sleep(g_param['waitMainMenu']/2)
            return

        # Otherwise, assume we are on the main menu and try to click on
        # MATS Perform Query image.
        else:
            imgs = g_bd.d.find_elements_by_tag_name('img')
            i=1
            for img in imgs:
                if (img.get_attribute('src').find(g_mats['imageLinkPerform'])\
                    >= 0
                    ):
                    test = ActionChains(g_bd.d)
                    test.move_to_element_with_offset(img, 158, 1)
                    test.click()
                    self.focusActiveElement()
                    test.perform()
                    # Give some time for the click to take effect.
                    time.sleep(g_param['waitMainMenu'])
                    return

            # If no appropriate image/link has been found, go back to eQ home
            # and try again.
            self.goToHome()
            return self.goToMatsPerformQuery()
Ejemplo n.º 5
0
	def parse(self,response):
		self.driver.get(response.url)
		self.driver.find_element_by_xpath('//div[@class="ui-state-default icon-div jQButtonNoWidth"]').click()
		time.sleep(1)
		targets = self.driver.find_elements_by_xpath('//a[@class="actionLink "]')
		scrollNum = len(self.driver.find_elements_by_xpath('//tr[@class="odd"]')[0].find_elements_by_xpath('.//td'))
		count = 0
		for target in targets:
			target.click()
			time.sleep(1)
			show = target.text
			date = self.driver.find_element_by_xpath('//div[@class="show-date"]').text
			scrollbar = self.driver.find_element_by_xpath('//div[@class="touchcarousel-wrapper auto-cursor"]')
			action = ActionChains(self.driver)
			action.move_to_element(scrollbar)
			action.click()
			for i in range(1,4):
				action.send_keys(Keys.ARROW_RIGHT)
			action.perform()
			time.sleep(1)
			count = count + 1
			links = self.driver.find_elements_by_xpath('//a[@class="product-description"]')
			for link in links:
				url = link.get_attribute("href")
				request = scrapy.Request(response.urljoin(url), self.parse_product)
				request.meta['day'] = date
				request.meta['show'] = show
				print len(targets)
				yield request
Ejemplo n.º 6
0
def search_brand(item, name):
    '''搜需要的品牌'''
    print 'in search_brand',item,name
    try:  # 如果找不到,就直接return
        lis = driver.find_elements_by_class_name(item)
    except:
        print platfm.local_str('没有' + item + '条目,返回')
        return
    print 'after find'
    # driver.set_page_load_timeout(0.5) #0.5s超时,太短的话(0.1s)click可能会超时
    driver.set_page_load_timeout(4)  # 等待嵌套页面加载需要的时间较长
    for li in lis:
        info = li.find_element_by_class_name(name).text
        print info
        # 至少包括Brands里的一项,包括Keys里的所有项
        if (filter(lambda x: x.lower() in info.lower(), Brands) and
                (Keys and Keys == filter(lambda x: x.lower() in info.lower(),
                 Keys) or not Keys)):
            global MixFlag
            if u"男女" in info:
                MixFlag = True
            action = ActionChains(driver)
            action.click(li).perform()
            print 'after click'
            time.sleep(5)
            print 'after sleep'
            # 切换到新的窗口
            print 'go into ' + info
            page.switch_do(driver, process)
            MixFlag = False
Ejemplo n.º 7
0
def nest_page(driver):
    '''处理嵌套页面的情况:页面内又含有分支页面'''
    print 'in nest_page'
    global Depth
    if Depth <= 1:  # 深度最多为1层
        try:
            driver.find_element_by_class_name('pro_list_pic')
        except NoSuchElementException:
            Depth += 1
            print 'need to jump again'
            eles = driver.find_elements_by_tag_name('a')
            pattern = re.compile('show-\d+.html$')
            for ele in eles:
                if pattern.search(str(ele.get_attribute('href'))):
                    print 'before click'
                    action = ActionChains(driver)
                    action.click(ele).perform()
                    print 'after click'
                    # 切换到新的窗口
                    base_page = ele.get_attribute('href')
                    print 'go into ' + base_page
                    try:
                        driver.current_url
                    except:
                        pass
                    page.switch_do(driver, process, base_page)
            Depth -= 1
            return
Ejemplo n.º 8
0
    def mouse_move_to_random_one(self):
        try:
            searchResultsInColumn_ss = self.driver.find_elements_by_css_selector(ResultPageMap['searchResultAdContainerCss'])
            results_random_ss = random.choice(searchResultsInColumn_ss)
            global random_one_creativeid_ss
            random_one_creativeid_ss = results_random_ss.get_attribute("creativeid")
            print "The random selected one from the results list is %s." % random_one_creativeid_ss

            self.wait_for_element_visibility(5,
                                             "cssSelector",
                                             ".adcontainer[creativeid='" + random_one_creativeid_ss + "']"
            )
            random_one = self.find_element("cssSelector",
                                           ".adcontainer[creativeid='" + random_one_creativeid_ss + "']"
            )

            actions = ActionChains(self.driver)
            actions.move_to_element(random_one)
            print "actions - move mouse to element"
            actions.click(random_one)
            print "actions - click the element"
            actions.perform()
            print "actions - done"
        except:
            raise IncorrectPageException
Ejemplo n.º 9
0
Archivo: page.py Proyecto: 2gis/mapsapi
 def click(self):
     """
     Left-clicks the current cursor position
     """
     from selenium.webdriver.common.action_chains import ActionChains
     act = ActionChains(self.test)
     act.click().perform()
Ejemplo n.º 10
0
def add_to_shimo(content):
	driver = webdriver.Chrome(sys.argv[1])  # Optional argument, if not specified will search path.
	#driver.add_cookie({'name' : 'session', 'value' : 'eyJfaWQiOnsiIGIiOiJaalUyTm1aak5EVTRPRE5qWWpVNU9HWmtNalZoWmpBNE4yUTNaR016TkRrPSJ9fQ', 'path' : '/'})
	driver.implicitly_wait(0)
	driver.get('https://www.shimo.im/')
	cookies = pickle.load(open("cookies.pkl", "rb"))
	for cookie in cookies:
		driver.add_cookie(cookie)
	driver.get('https://www.shimo.im/doc/g8XvnVEvCtEWnvrB')
	try:
		search_box = driver.find_element_by_class_name('locate')
		mouse = ActionChains(driver)
		mouse.move_to_element_with_offset(search_box, 0, 0)
		mouse.click()
		mouse.send_keys(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ': %s\n' % content)
		mouse.perform()
	except:
		mouse = ActionChains(driver)
		mouse.move_by_offset(290, 400)
		mouse.click()
		mouse.send_keys(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ': %s\n' % content)
		mouse.perform()
		
	time.sleep(5)
	driver.quit()
Ejemplo n.º 11
0
    def test_vessel_track(self):
        driver = server.driver
        try:
            driver.set_window_size(1280, 776)
            driver.get("http://*****:*****@class='animations']/div/div/div[2]"), point['x'], point['y'])
            actions.click()
            actions.perform()

            server.wait_for(lambda: self.animationHasLoaded("VesselTrackAnimation"))

            self.assertEqual(self.getHover(point, "ClusterAnimation"), 27200, "Seriesgroup not present at x,y")

        except:
            name = os.path.realpath("ui_tests.test.test_home.png")
            driver.get_screenshot_as_file(name)
            raise
Ejemplo n.º 12
0
    def test_zoom(self):
        driver = server.driver
        try:
            driver.set_window_size(1280, 776)
            driver.get("http://*****:*****@title="Zoom in"]'))
            actions.perform()

            time.sleep(1)
            server.wait_for(lambda: self.animationHasLoaded("ClusterAnimation"))

            self.assertEqual(get_tiles(), [u'-11.25,-11.25,0,-5.625', u'-11.25,-16.875,0,-11.25', u'-11.25,-5.625,0,0', u'-11.25,0,0,5.625', u'-11.25,11.25,0,16.875', u'-11.25,5.625,0,11.25', u'-22.5,-11.25,-11.25,-5.625', u'-22.5,-16.875,-11.25,-11.25', u'-22.5,-5.625,-11.25,0', u'-22.5,0,-11.25,5.625', u'-22.5,11.25,-11.25,16.875', u'-22.5,5.625,-11.25,11.25', u'-33.75,-11.25,-22.5,-5.625', u'-33.75,-16.875,-22.5,-11.25', u'-33.75,-5.625,-22.5,0', u'-33.75,0,-22.5,5.625', u'-33.75,11.25,-22.5,16.875', u'-33.75,5.625,-22.5,11.25', u'0,-11.25,11.25,-5.625', u'0,-16.875,11.25,-11.25', u'0,-5.625,11.25,0', u'0,0,11.25,5.625', u'0,11.25,11.25,16.875', u'0,5.625,11.25,11.25', u'11.25,-11.25,22.5,-5.625', u'11.25,-16.875,22.5,-11.25', u'11.25,-5.625,22.5,0', u'11.25,0,22.5,5.625', u'11.25,11.25,22.5,16.875', u'11.25,5.625,22.5,11.25', u'22.5,-11.25,33.75,-5.625', u'22.5,-16.875,33.75,-11.25', u'22.5,-5.625,33.75,0', u'22.5,0,33.75,5.625', u'22.5,11.25,33.75,16.875', u'22.5,5.625,33.75,11.25'])

        except:
            name = os.path.realpath("ui_tests.test.test_zoom.png")
            driver.get_screenshot_as_file(name)
            raise
	def web_hover_and_click(self, elementToHover_locator, elementToClick_locator, elementToHover_selected_num=1, elementToClick_selected_num=1):
		"""Hover and click ,复合操作命令
		elementToHover_locator:       同Selenium2Library里的locator, 指定hover目标元素-hover的区域位置.
		elementToClick_locator:       同Selenium2Library里的locator, 指定hover后出现的目标元素-要点击的元素位置.
		elementToHover_selected_num:  指定hover目标元素序号.
		elementToClick_selected_num:  指定hover后出现的目标元素序号.
		[不输入(默认值):  点击第一个元素];
		[=0 :               点击最后一个元素]; 
		[=x(>0):          点击第x个元素].


		一般使用方法:
		| Web Hover And Click | xpath=//div[3]/ul/li[1] | xpath=//div[3]/ul/li[1]/span[2]/a[3] |
		| Web Hover And Click | ${elementToHover_locator} | ${elementToClick_locator} |
		带seleted_num使用方法:
		注意 locators的xpath表达方式以及seleted_num的设定,需要保持hover元素和点击元素的一致性
		| Web Hover And Click | xpath=//div/div[3]/ul/li | xpath=//span[2]/a[3] | 2 | 2 |
		| Web Hover And Click | ${elementToHover_locators} | ${elementToHover_locators} | 0 | 0 |
		(在运行该KW会将浏览器窗口移到你看不到的地方,以后也别想看到,屏幕截图是好的,哈哈~~)
		"""
		#self._current_browser().set_window_size(100, 100)#设置窗口大小
		self._current_browser().set_window_position(-10000, -10000)#设置窗口位置将窗口移出桌面。。。
		self._info("Hover '%s' and click '%s'" % (elementToHover_locator, elementToClick_locator))
		elementToHover = self._get_selected_element(elementToHover_locator, elementToHover_selected_num)
		elementToClick = self._get_selected_element(elementToClick_locator, elementToClick_selected_num)
		if elementToHover is None:
			raise AssertionError("ERROR: Element %s not found." % (elementToHover_locator))
		if elementToClick is None:
			raise AssertionError("ERROR: Element %s not found." % (elementToClick_locator))
		actions = ActionChains(self._current_browser())
		actions.move_to_element(elementToHover)
		#actions.move_to_element(elementToClick)
		actions.click(elementToClick)
		actions.perform()
		self._current_browser().set_window_position(0, 0)#移回来了。。
Ejemplo n.º 14
0
    def click_menu_option_by_visible_text(self, menu_locator,
                                          list_of_menu_options):
        """
        Performs a move_to_element action on every link <a...> contained in
        menu_locator if its visible text matches any of the names defined in
        list_of_menu_options and clicks on the last matching link.


        """
        menu_options = self.driver.find_elements(*menu_locator)
        actions = ActionChains(self.driver)
        menu_index = 0
        expected_option = None
        for option in menu_options:
            if menu_index >= len(list_of_menu_options):
                break
            if expected_option is None:
                expected_option = list_of_menu_options[menu_index].strip()

            if (option.get_attribute('title') == expected_option or
                    option.get_attribute('text') == expected_option or
                    option.text == expected_option):
                actions.move_to_element(option)
                menu_index += 1
                expected_option = None
        actions.click()
        actions.perform()
Ejemplo n.º 15
0
    def test_home(self):
        driver = server.driver
        try:
            driver.set_window_size(1280, 776)
            driver.get("http://*****:*****@class='animations']/div/div/div[2]"), point['x'], point['y'])
            actions.click()
            actions.perform()

            server.wait_for(lambda: not server.is_element_present('//div[@id="vessel_identifiers"]//table//td[@class="imo"]'))
            self.failUnless(server.is_element_present('//div[@id="vessel_identifiers"]//table//td[text()="27200"]'))
        except:
            name = os.path.realpath("ui_tests.test.test_home.png")
            driver.get_screenshot_as_file(name)
            raise
 def test2_language_dropdown(self):
     # check language options dropdown on the page
     self.assertTrue(self.is_element_present(By.XPATH, '//span[@class="lng"]'))
     dropdown = self.driver.find_element_by_xpath('//li[@class="language-selector"]/ul')
     de_lang = self.driver.find_element_by_xpath('//li[@class="not-current"]/a/span[text()="de"]')
     hover = ActionChains(self.driver).move_to_element(dropdown).move_to_element(de_lang)
     hover.click().perform()
Ejemplo n.º 17
0
	def parse(self, response):
		self.driver.get(response.url)
		try:
			WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, '//a[@class="list-name"]')))
		except TimeoutException:
			return
		resp = TextResponse(url=self.driver.current_url, body=self.driver.page_source, encoding='utf-8')
		urls = resp.xpath('//a[@class="list-name"]/@href').extract()
		old = 0
		new = len(urls)
		while old != new:
			print "\n\n\n",old,new,"\n\n\n"
			for i in xrange(old,new):
				abs_url = 'http://www.housing.com' + urls[i]
				yield scrapy.Request(abs_url, callback=self.parse_property_info)
			try :
				link = self.driver.find_element_by_xpath('//div[@class="show-more-container"]')
				actions = ActionChains(self.driver)
				actions.click(link)
				actions.perform()
			except:
				self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
			time.sleep(3)
			resp = TextResponse(url=self.driver.current_url, body=self.driver.page_source, encoding='utf-8')
			urls = resp.xpath('//a[@class="list-name"]/@href').extract()
			old = new
			new = len(urls)
Ejemplo n.º 18
0
    def test_logged_in_users_lists_are_saved_as_my_lists(self):
        # Edith is a logged-in user
        edith_email = '*****@*****.**'
        edith_user_url= '/' + 'lists' + '/' + 'users' + '/' + edith_email + '/'
        self.create_pre_authenticated_session(edith_email)

        # She goes to the home page and starts a list
        self.browser.get(self.server_url)
        self.get_item_input_box().send_keys('Reticulate splines\n')
        self.get_item_input_box().send_keys('Immanentize eschaton\n')
        first_list_url = self.browser.current_url

        # She notices a "My lists" link, for the first time.
        element = self.browser.find_element_by_xpath("//a[@href='" + edith_user_url + "']")
        action = ActionChains(self.browser)
        sleep(5)
        action.click(element).perform()


        # she sees that her list is named according to its first line 
        element = self.browser.find_element_by_xpath("//a[contains(text(), 'Reticulate splines')]")
        action = ActionChains(self.browser)
        sleep(5)
        action.click(element).perform()
        self.wait_for(
            lambda: self.assertEqual(self.browser.current_url, first_list_url)
        )
       

        # She decides to start another list, just to see
        self.browser.get(self.server_url)
        self.get_item_input_box().send_keys('Click cows\n')
        second_list_url = self.browser.current_url

        
        # She goes back to her lists page to see if the second one is there
        element = self.browser.find_element_by_xpath("//a[@href='" + edith_user_url + "']")
        action = ActionChains(self.browser)
        sleep(5)
        action.click(element).perform()
        
        # SHe clicks on it and checks the url of the new list
        element = self.browser.find_element_by_xpath("//a[contains(text(), 'Click cows')]")
        action = ActionChains(self.browser)
        sleep(5)
        action.click(element).perform()
        self.wait_for(
            lambda: self.assertEqual(self.browser.current_url, second_list_url)
        )

        # She logs out.  The "My lists" option disappears
        element = self.browser.find_element_by_xpath("//a[contains(text(), 'Log out')]")
        action = ActionChains(self.browser)
        sleep(5)
        action.click(element).perform()
        #self.browser.find_element_by_id('id_logout').click()
        self.assertEqual(
            self.browser.find_elements_by_link_text('My lists'),
            []
        )
Ejemplo n.º 19
0
    def parse(self, response):
        while self.roll < 1409110903:
            self.driver.get('http://new.aktu.co.in/')
            try:
                WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH,'//*[@id="ctl00_ContentPlaceHolder1_divSearchRes"]/center/table/tbody/tr[4]/td/center/div/div/img')))
            except:
                continue
	        # Sync scrapy and selenium so they agree on the page we're looking at then let scrapy take over
            resp = TextResponse(url=self.driver.current_url, body=self.driver.page_source, encoding='utf-8');
            rollno = self.driver.find_element_by_name('ctl00$ContentPlaceHolder1$TextBox1')
            rollno.send_keys(self.roll)
            captcha_url = format(resp.xpath('//*[@id="ctl00_ContentPlaceHolder1_divSearchRes"]/center/table/tbody/tr[4]/td/center/div/div/img/@src').extract())
            url = "http://new.aktu.co.in/" + captcha_url[3:-2]
            print url
            captcha = url_to_image(url)
            captcha_value = read_captcha(captcha)
            print captcha_value
            captcha_input = self.driver.find_element_by_name('ctl00$ContentPlaceHolder1$txtCaptcha')
            captcha_input.send_keys(captcha_value)
            input()
            submit = self.driver.find_element_by_name('ctl00$ContentPlaceHolder1$btnSubmit')
            actions = ActionChains(self.driver)
            actions.click(submit)
            actions.perform()
            resp = TextResponse(url=self.driver.current_url, body=self.driver.page_source, encoding='utf-8');
            if "Incorrect Code" in format(resp.xpath('*').extract()):
                continue
            self.parse_result(self.driver.current_url)
            self.roll += 1
        self.count +=3
        self.sheet.write(self.count,0,"First")
        self.sheet.write(self.count,1,self.top[0][0])
        self.sheet.write(self.count+1,0,"Last")
        self.sheet.write(self.count+1,1,self.top[1][0])
        return
Ejemplo n.º 20
0
 def click_and_move(self, elemet_css, target_css):
     # driver = self.driver
     element = self.driver.find_element_by_css_selector(elemet_css)
     target = self.driver.find_element_by_css_selector(target_css)
     action = ActionChains(self.driver).click_and_hold(element).move_to_element(target)
     time.sleep(3)
     action.click().perform()
Ejemplo n.º 21
0
	def test_free_preicing_login_paid_pricing_in_dashboard_page(self):
		driver = self.driver
		CommonFun.siginInPm(driver, config["paid_pricing"]["H2_USERNAME"], config["paid_pricing"]["H2_PASSWORD"])

		driver.get(config["DASHBOARD_URL"])
		print "\n **** start test permission (paid_pricing account) ****"

		reminder = driver.find_element_by_class_name("reminder")
		ActionChains(driver).move_to_element(reminder).click().perform()
		CommonFun.closeClinicPaidAlert(driver, "reminder")
		reminder_clost_btn = driver.find_element(By.ID, "reminderCloseBtn")
		reminder_clost_btn.click()

		driver.find_element_by_id("navGroups").click()
		CommonFun.closeClinicPaidAlert(driver, "nav - groups")

		nav_admiinistration = driver.find_element_by_id("navAdministration")
		action = ActionChains(driver)
		action.move_to_element(nav_admiinistration)
		action.click()
		action.move_to_element(driver.find_element(By.ID, "menuBroadcast"))
		action.click()
		action.perform()
		CommonFun.closeClinicPaidAlert(driver, "nav - Administration - Broadcast")

		driver.find_element_by_id("navAlerts").click()
		CommonFun.closeClinicPaidAlert(driver, "nav - Alerts")
def input_information(positives):
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get('http://vradhome/Privileging/Facility?facility')
    time.sleep(2)
    for k in range(len(positives)):
        fac_search = driver.find_element_by_id('s2id_autogen1')
        actions = ActionChains(driver)
        actions.move_to_element(fac_search)
        actions.click()
        actions.send_keys(positives[k][2]).perform()
        time.sleep(2)
        actions = ActionChains(driver)
        actions.send_keys(Keys.RETURN).perform()
        driver.implicitly_wait(10)
        ex_test = driver.find_elements_by_class_name("expand")
        # maybe avoide C2
        if len(ex_test) < 3:
            continue
        else:
            try:
                driver.implicitly_wait(20)
                name_spot = driver.find_element_by_xpath(
                    "//*[contains(text(), '{0}')]".format(positives[k][1]))
                driver.execute_script("return arguments[0].scrollIntoView();",name_spot)
                actions = ActionChains(driver)
                actions.move_to_element(name_spot).click().perform()
                expand = driver.find_elements_by_class_name("expand")[2]
                driver.execute_script("return arguments[0].scrollIntoView();",expand)
                expand.click()
                tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).strftime('%m/%d/%y')
                next_act = driver.find_elements_by_class_name("form-control")[0]
                comment = driver.find_elements_by_class_name("form-control")[9]
                actions = ActionChains(driver)
                actions.move_to_element(next_act).click()
                actions.send_keys('{0}'.format(tomorrow))
                actions.send_keys(Keys.TAB).perform()
                actions = ActionChains(driver)
                actions.send_keys("See Note (Rad Leaving)").perform()
                actions = ActionChains(driver)
                actions.move_to_element(comment).click().send_keys(
                    'Rad last read date on: {0}. Please stop app'
                    ' process and update status to WD. Please contact'
                    ' Roberta with questions.'.format(positives[k][0])
                    ).perform()
                
                driver.find_element_by_xpath('//*[@title="Submit Mass Update"]').click()
                time.sleep(7)
                print('{0} : {1} \nRad last read date on: {2}.\n'.format(
                      positives[k][1],positives[k][2],positives[k][0]))
                
            except selenium.common.exceptions.NoSuchElementException:
                    print("** Unable to find {0} at {1} **\n".format(positives[k][1].encode('ascii','ignore')
                                                                     ,positives[k][2].encode('ascii','ignore')))
            continue
          
        
        time.sleep(3)
    driver.quit()
Ejemplo n.º 23
0
 def write(self, text):
     element = self.get_element()
     input_field = element.find_element_by_xpath("./following-sibling::input")
     actions = ActionChains(self.driver)
     actions.click(on_element=element)
     actions.send_keys_to_element(input_field, text)
     actions.perform()
     time.sleep(2)
Ejemplo n.º 24
0
def step_impl(context):
    elem = find_css_class_with_wait(context, STEP_NUMBER_CLASS)
    actions = ActionChains(context.browser)
    # Move the mouse postion to the top left of the element, and
    # then offset the position. Should lay outside of the element.
    actions.move_to_element_with_offset(elem, -50, -50)
    actions.click()
    actions.peform()
Ejemplo n.º 25
0
 def shop_button_second_slide_click(self):
     self._driver.find_element(*HomePage.second_products_slide).click()
     action = ActionChains(self._driver)
     action.key_down(Keys.SHIFT)
     time.sleep(2)
     action.click(self._driver.find_element(*HomePage.shop_button_second_slide))
     action.key_up(Keys.SHIFT)
     action.perform()
Ejemplo n.º 26
0
def give_some_input(context, input_element, text):
    if context.mist_config.get(text):
        text = context.mist_config[text]
    actions = ActionChains(context.browser)
    actions.move_to_element(input_element)
    actions.click(input_element)
    actions.send_keys(text)
    actions.perform()
Ejemplo n.º 27
0
 def closeOpenedTabs(self):
     closeElements = self.driver.find_elements_by_xpath("//img[contains(@src,'close.png')]")  
     for element in closeElements:
         try:
             actionChains = ActionChains(self.driver)
             actionChains.click(element).perform()
         except MoveTargetOutOfBoundsException:
             pass
def post(driver,content):
	driver.get("https://www.facebook.com")
	action= ActionChains(driver)
	post = driver.find_element_by_name("xhpc_message")
	action.click(post)
	action.perform()
	post.send_keys(content)
	post.submit()
Ejemplo n.º 29
0
 def move_to_and_click(self, x=0, y=0):
     # self._parent.execute_script(simulate_event('mouseover'), self)
     if x and y:
         action_chains = ActionChains(self._parent).move_to_element_with_offset(super(WebElement, self), x, y)
     else:
         action_chains = ActionChains(self._parent).move_to_element(super(WebElement, self))
     action_chains.click().perform()
     return self
Ejemplo n.º 30
0
def click_element_with_offset(driver, elem, x, y):
    action = ActionChains(driver)
    echo_print("Moving to x position", x)
    echo_print("Moving to y position", y)
    action.move_to_element_with_offset(elem, x, y)
    print("OK now see where the mouse is...")
    action.click()
    action.perform()
Ejemplo n.º 31
0
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

#chromedriver的绝对路径
driver_path = r'D:\Program Files (x86)\chromedriver\chromedriver.exe'

driver = webdriver.Chrome(executable_path=driver_path)

# 请求网页
#driver.get('https://www.douban.com/')

driver.get('https://www.baidu.com')
inputTag = driver.find_element_by_id('kw')
submitTag = driver.find_element_by_id('su')

submitTag.click()
actions = ActionChains(driver)
actions.move_to_element(inputTag)
actions.send_keys_to_element(inputTag, 'python')
actions.move_to_element(submitTag)
actions.click(submitTag)
actions.perform()  #开始执行
'''
click_and_hold(element):点击但不松开鼠标。
context_click(element):右键点击。
double_click(element):双击。 更多方法请参考:http://selenium-python.readthedocs.io/api.html
'''
Ejemplo n.º 32
0
    def get_data(self, vin_list):
        self.driver.get(
            'http://gwms.kiacdn.com/jsp_html5/w400_basic_data/w400_0103/W400_0103.jsp'
        )
        sleep(2)
        vin_dict = {}
        z = 0
        print("Время начала: {}".format(str(datetime.datetime.now())))
        for vin in vin_list:
            persent = round(z / len(vin_list) * 100, 2)
            print("Выполнено: {}%".format(str(persent)), end='\r')
            i = 0
            while i < 18:
                self.driver.find_element_by_id('txtVIN').send_keys(
                    Keys.BACK_SPACE)
                i += 1
            start = True
            while start:
                try:
                    self.driver.find_element_by_id('txtVIN').send_keys(vin)
                    search_btn = self.driver.find_element_by_id("btnInq")
                    search_btn.click()
                    service1 = self.driver.find_element_by_id(
                        'plsDataGrid_userCtrl_0_2_0')
                    hov = ActionChains(self.driver).move_to_element(service1)
                    hov.perform()
                    hov.click()
                    z_dic = {}
                    start = False
                except:
                    sleep(2)

            for i in range(10):
                start = True
                while start:
                    try:
                        inner_dic = {}
                        if self.driver.find_element_by_id('plsDataGrid_userCtrl_'+str(i)+'_2_0').get_attribute('value') == '' \
                        and self.driver.find_element_by_id('plsDataGrid_userCtrl_'+str(i)+'_4_0').get_attribute('value') == '0':
                            continue
                        inner_dic['service'] = self.driver.find_element_by_id(
                            'plsDataGrid_userCtrl_' + str(i) +
                            '_1_0').get_attribute('value')
                        inner_dic['order'] = self.driver.find_element_by_id(
                            'plsDataGrid_userCtrl_' + str(i) +
                            '_2_0').get_attribute('value')
                        inner_dic['date'] = self.driver.find_element_by_id(
                            'plsDataGrid_userCtrl_' + str(i) +
                            '_3_0').get_attribute('value')
                        inner_dic['odometr'] = self.driver.find_element_by_id(
                            'plsDataGrid_userCtrl_' + str(i) +
                            '_4_0').get_attribute('value')
                        inner_dic['dealer'] = self.driver.find_element_by_id(
                            'plsDataGrid_userCtrl_' + str(i) +
                            '_5_0').get_attribute('value')
                        if inner_dic['service'] != '' and inner_dic[
                                'date'] != '':
                            z_dic[i] = inner_dic
                        start = False
                    except:
                        sleep(3)
            vin_dict[vin] = z_dic
            with open('info.txt', 'a') as file:
                file.write(vin + ': ' + str(vin_dict[vin]) + '\n')
            z += 1
        print("Время окончания: {}".format(str(datetime.datetime.now())))
        # for key, val in vin_dict.items():
        #     print(key, '  ', val)
        self.driver.quit()
Ejemplo n.º 33
0
# Maximum number of each product
MAX = 1
CLICKS = 10000  # Number of times to click the big cookie

# This is block the execution of the driver for 5 seconds
driver.implicitly_wait(5)  # for the site to load

cookie = driver.find_element_by_id('bigCookie')
count = driver.find_element_by_id('cookies')

actions = ActionChains(
    driver)  # instance of ActionChains that allows us perform various actions

# clicks the cookie element
actions.click(
    cookie)  # adds to the queue but doesnt execute until perform() is called

items = [driver.find_element_by_id(f'product{i}') for i in range(17, -1, -1)]

for i in range(CLICKS):
    actions.perform()  # executes the action in the queue
    try:
        curr = int(count.text.split(" ")[0])  # current number of cookies
    except ValueError:
        curr = int(''.join(curr.split(',')))

    for item in items:
        try:
            lines = item.text.splitlines()
            product_name, price = lines[0], lines[1]
            owned = lines[2] if len(lines) >= 3 else 0
    def get_authorizations(self):
        """Get all the authorizations from firstdata for parsing into the firstdata.authorization table"""
        mn = Main()
        mid_to_search = mn.get_mid_search()

        """Get a csv from youraccessone transactions"""
        display = Display(visible=0, size=(800, 600))
        display.start()

        driver_builder = DriverBuilder()
        browser = driver_builder.get_driver(dwn, headless=False)

        browser.get('https://www.youraccessone.com')

        username = browser.find_element_by_id("txtUserName")
        password = browser.find_element_by_id("txtPassword")

        username.send_keys(os.environ['username'])
        password.send_keys(os.environ['password'])

        browser.find_element_by_name("uxLogin").click()

        time.sleep(1)
        # go to authorizations
        element_to_hover_over = browser.find_element_by_xpath(
            "//*[text()='Reports ']")
        hover = ActionChains(browser).move_to_element(element_to_hover_over).move_to_element(browser.find_element_by_xpath(
            "//*[text()='Authorization Log']")).move_to_element(browser.find_element_by_xpath(
                "//*[text()='Authorizations']"))
        hover.click().perform()

        """open filter"""
        browser.find_element_by_xpath("//*[text()='FILTER']").click()

        """toggle daily"""
        #browser.find_element_by_xpath("//*[text()='Daily']").click()

        """This section for date range not currently used change Daily to Date Range then uncomment"""
        """get date range"""
        start = browser.find_element_by_id("ctl00_ContentPage_uxFiltering_uxReportFilter_dpFromDate_dateInput")
        start.clear()
        start.send_keys('03-24-2016')

        end = browser.find_element_by_id('ctl00_ContentPage_uxFiltering_uxReportFilter_dpToDate_dateInput')
        end.clear()
        end.send_keys('03-26-2018')

        """check all merchants"""

        for item in mid_to_search:
            # fill in the field
            browser.find_element_by_id(
                "ctl00_ContentPage_uxFiltering_uxReportFilter_ctl00_Input").click()
            time.sleep(2)
            browser.find_element_by_xpath("//*[text()='Merchant Number']").click()
            text_box = browser.find_element_by_id("ctl00_ContentPage_uxFiltering_uxReportFilter_inMERCHANTNUMBER")
            text_box.clear()
            text_box.send_keys(item)

            # submit to apply filters
            try:
                browser.find_element_by_id("ctl00_ContentPage_uxFiltering_uxReportFilter_btSubmit").click()

                time.sleep(2)

                # download transaction
                count = 0
                element_to_hover_over = browser.find_element_by_xpath(
                    "//*[text()='EXPORT']")
                hover = ActionChains(browser).move_to_element(element_to_hover_over)
                hover.perform()

                browser.find_element_by_xpath("//*[text()='CSV']").click()
                time.sleep(2)

            except NoSuchElementException:
                continue

        browser.quit()
        display.stop()
Ejemplo n.º 35
0
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get('https://orteil.dashnet.org/cookieclicker/')

driver.implicitly_wait(5)

cookie = driver.find_element_by_id('bigCookie')
cookie_count = driver.find_element_by_id('cookies')

items = [
    driver.find_element_by_id('productPrice' + str(i))
    for i in range(1, -1, -1)
]

actions = ActionChains(driver)
actions.double_click(cookie)

for i in range(5000):
    actions.perform()
    count = int(cookie_count.text.split(' ')[0])

    for item in items:
        value = int(item.text)
        if value <= count:
            upgrade_actions = ActionChains(driver)
            upgrade_actions.move_to_element(item)
            upgrade_actions.click()
            upgrade_actions.perform()
Ejemplo n.º 36
0
 def action_perfom(self, ele):
     action = ActionChains(self.driver)
     action.click(ele).perform()
Ejemplo n.º 37
0
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

PATH = "/home/chaitanya/chromedriver"
driver = webdriver.Chrome(PATH)

driver.get("https://orteil.dashnet.org/cookieclicker/")

driver.implicitly_wait(7)

cookie = driver.find_element_by_id("bigCookie")
cookie_count = driver.find_element_by_id("cookies")
items = [driver.find_element_by_id("productPrice" + str(i)) for i in range(1,-1,-1)]

actions = ActionChains(driver)
actions.click(cookie)

for num_times in range(10):
    actions.perform()

#search = driver.find_element_by_name("s")
#print(search)
#search.send_keys('test')
#search.send_keys(Keys.RETURN)

#print(driver.page_source) 
#link = driver.find_element_by_link_text('Python Programming')
#link.click()
Ejemplo n.º 38
0
def job1():
    #获取 chrome 驱动器
    driver = webdriver.Chrome(
        executable_path=r'/Applications/Python 3.7/chromedriver')
    url = r'http://s.3dker.cn'  #设置网页链接
    driver.get(url)  #打开谷歌网页

    #登录
    username = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div/form/div[1]/div/div[1]/input')
    username.clear()
    username.send_keys(r'13216116777')
    password = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div/form/div[2]/div/div[1]/input')
    password.clear()
    password.send_keys(r'o9i8u7y6')
    login_button = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div/form/div[3]/div/button')
    login_button.click()
    time.sleep(2)

    #进入打印订单
    order_menu = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[1]/ul/li[2]/div')
    order_menu.click()
    time.sleep(2)
    printOrder_menu = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[1]/ul/li[2]/ul/li[3]')
    printOrder_menu.click()
    time.sleep(2)

    #输入日期
    date = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[2]/div/div/div[2]/form/div/div/div/div/div/div/div[1]/div/input'
    )
    from_date = "".join(time.strftime('%Y-%m', time.localtime(
        time.time()))) + '-01'  #开始时间=当前年月+01
    to_date = time.strftime('%Y-%m-%d',
                            time.localtime(time.time()))  #结束时间=当前年月日
    complete_date = from_date + ' - ' + to_date  #拼接
    delte_date = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[2]/div/div/div[2]/form/div/div/div/div/div/div/div[1]/div/i'
    )
    delte_date.click()  #点击日期组件中的按键达到清空原来日期的目的
    date.send_keys(complete_date)  #输入准备好的日期

    #搜索
    search = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[2]/div/div/div[2]/form/button/span')
    search.click()
    time.sleep(2)

    #进入销售额 tab 页下
    sales = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[2]/div/div/div[3]/div[1]/div/div/div/div/div[3]'
    )
    sales.click()
    time.sleep(2)

    #鼠标行为
    chain = ActionChains(driver)
    # 通过printOrder_menu这个点已成功凑出了偏移点(而在尝试通过计算,试图从其他点来再次定位到偏移点时,却失败了)
    chain.move_to_element(printOrder_menu)  #先移动到这个元素,即当前鼠标停留在该元素的坐标
    chain.move_by_offset(564, 338)  #从当前的鼠标坐标开始移动到(x+564,y+338)
    chain.click().perform()

    #保存图片
    pic_path = '/Users/shining3d/Desktop/1/1' + '.png'
    driver.save_screenshot(pic_path)  #截取chrome当前屏幕
    global pic_path2  #global声明全局变量
    pic_path2 = '/Users/shining3d/Desktop/1/' + to_date + '.png'

    #canvas定位(为了获得canvas的宽高来估算即将裁图的区域大小)
    canvas = driver.find_element_by_xpath('//*[@id="chart"]/div[1]/canvas')
    # 裁图起点定位
    start = driver.find_element_by_xpath(
        '//*[@id="app"]/div/div[1]/div/div[2]/div/div/div[1]/div/span[1]/a')
    #获得裁图起点的坐标
    left = start.location['x']
    top = start.location['y']
    #裁图大小(宽高度)
    elementWidth = start.location['x'] + canvas.size['width']
    elementHeight = start.location['y'] + canvas.size[
        'height'] + 160  #+160是 起点与canvas的高度补差

    picture = Image.open(pic_path)  #读取从chrome截取的图片
    picture = picture.crop((left, top, elementWidth, elementHeight))  #裁取设定的区域
    picture.save(pic_path2)

    time.sleep(1)  #睡眠
    driver.quit()  #关闭浏览器
Ejemplo n.º 39
0
    def test_interactions(self):
        # VARIABLES
        drag_error = "Unable to drag Cytoscape nodes properly"
        click_error = "Unable to click Cytoscape nodes properly"
        mouseover_error = "Unable to mouseover Cytoscape nodes properly"

        # View module docstring for more information about initial positions
        init_pos = {
            'Node 1': (59, 182),
            'Node 2': (222, 345),
            'Node 3': (168, 283 - 20),
            'Node 4': (440, 182),
            'Node 5': (277, 236),
            'Node 6': (168, 283)
        }
        init_x, init_y = init_pos['Node 1']

        # Initialize the apps
        app = importlib.import_module('usage-events').app
        self.startServer(app)
        WebDriverWait(self.driver, 20).until(
            EC.presence_of_element_located((By.ID, "cytoscape")))

        actions = ActionChains(self.driver)

        # FUNCTIONS
        def save_screenshot(dir_name, name):
            directory_path = os.path.join(os.path.dirname(__file__),
                                          'screenshots', dir_name)

            # Create directory if it doesn't already exist
            if not os.path.exists(directory_path):
                os.makedirs(directory_path)

            self.driver.save_screenshot(
                os.path.join(os.path.dirname(__file__), 'screenshots',
                             dir_name, name + '.png'))

        def perform_dragging(x,
                             y,
                             delta_x,
                             delta_y,
                             elem,
                             dir_name='interactions'):
            """
            Performs dragging on a node, and return the difference from the start
            :param x: initial position of the node at the start of the action chain
            :param y: initial position of the node at the start of the action chain
            :param delta_x: how much we want to drag the node
            :param delta_y: how much we want to drag the node
            :param dir_name: The directory in which we store our screenshots
            :return: the difference between the position after drag and the starting position
            """
            actions.reset_actions()
            actions.move_to_element_with_offset(
                self.driver.find_element_by_tag_name('body'), x, y)
            actions.drag_and_drop_by_offset(source=None,
                                            xoffset=delta_x,
                                            yoffset=delta_y)
            actions.click()
            actions.perform()
            time.sleep(1)

            elem_json = json.loads(elem.text)
            new_pos = elem_json.get('renderedPosition')
            clicked_label = elem_json.get('data', {}).get('label')

            diff_x = round(new_pos['x'] - x)
            diff_y = round(new_pos['y'] - y)

            save_screenshot(
                dir_name,
                'Dragged{}By{}x{}y'.format(clicked_label.replace(' ', ''),
                                           diff_x, diff_y))

            return diff_x, diff_y

        def perform_clicking(x, y, elem, dir_name='interactions'):
            """
            :param x: The position on the screen where we want to click
            :param y: The position on the screen where we want to click
            :param elem: The element object from where we retrieve the JSON
            :param dir_name: The directory in which we store our screenshots
            :return: The label of element most recently clicked, if any
            """
            actions.reset_actions()
            actions.move_to_element_with_offset(
                self.driver.find_element_by_tag_name('body'), x, y)
            actions.click()
            actions.perform()

            time.sleep(1)
            clicked_label = json.loads(elem.text).get('data', {}).get('label')

            save_screenshot(dir_name,
                            'Clicked' + clicked_label.replace(' ', ''))

            return clicked_label

        def perform_mouseover(x, y, elem, dir_name='interactions'):
            actions.reset_actions()
            actions.move_to_element_with_offset(
                self.driver.find_element_by_tag_name('body'), x - 50, y)
            actions.move_by_offset(50, 0)
            actions.perform()
            time.sleep(1)

            mouseover_label = json.loads(elem.text).get('label')

            save_screenshot(dir_name,
                            'Mouseover' + mouseover_label.replace(' ', ''))

            return mouseover_label

        # Select the JSON output element
        elem_tap = self.driver.find_element_by_css_selector(
            'pre#tap-node-json-output')

        # Test dragging the nodes around
        offset_x, offset_y = perform_dragging(init_x, init_y, 0, 0, elem_tap)
        init_x += offset_x
        init_y += offset_y

        assert perform_dragging(init_x, init_y, 150, 0,
                                elem_tap) == (150, 0), drag_error
        assert perform_dragging(init_x + 150, init_y, 0, 150,
                                elem_tap) == (0, 150), drag_error
        assert perform_dragging(init_x+150, init_y+150, -150, -150, elem_tap) == (-150, -150), \
            drag_error

        # Test clicking the nodes
        for i in range(1, 7):
            label = 'Node {}'.format(i)
            assert perform_clicking(*init_pos[label],
                                    elem_tap) == label, click_error

        # Open the Mouseover JSON tab
        actions.move_to_element(
            self.driver.find_element_by_css_selector(
                '#tabs > div:nth-child(3)'))
        actions.click().perform()
        time.sleep(1)

        # Select the JSON output element
        elem_mouseover = self.driver.find_element_by_css_selector(
            'pre#mouseover-node-data-json-output')

        # Test hovering the nodes
        for i in range(1, 7):
            label = 'Node {}'.format(i)
            assert perform_mouseover(*init_pos[label],
                                     elem_mouseover) == label, mouseover_error
 def click_login(self):
     elets = self.find_element(*self.locator('login_loc'))
     action = ActionChains(self.driver)
     action.click(elets).perform()
Ejemplo n.º 41
0
 def button_click(self, button):
     hover = ActionChains(self.driver).move_to_element(button)
     hover.click().perform()
Ejemplo n.º 42
0
    def test_navbar(self):

        # Load CV page
        self.browser.get(self.live_server_url + '/cv')

        # User sees navbar
        navbartest = self.browser.find_elements_by_class_name('nav-link')
        navbar = []
        for item in navbartest:
            navbar.append(item.text)

        navbarelements = ['Home', 'Blog', 'CV', 'Log in']

        self.assertEqual(navbar, navbarelements)

        #User navigates to Homepage
        self.browser.find_element_by_link_text('Home').click()
        time.sleep(1)

        currenturl = self.browser.current_url

        self.assertEqual(currenturl, self.live_server_url + '/')

        #User goes back to CV page
        target = self.browser.find_element_by_class_name('resume')

        action = ActionChains(self.browser)

        action.move_to_element(target)
        action.click(target)
        action.perform()

        time.sleep(1)

        currenturl = self.browser.current_url

        self.assertEqual(currenturl, self.live_server_url + '/cv')

        #User navigates to Blog
        self.browser.find_element_by_link_text('Blog').click()
        time.sleep(1)
        currenturl = self.browser.current_url

        self.assertEqual(currenturl, self.live_server_url + '/blog')

        #User goes back to CV page
        self.browser.find_element_by_link_text('CV').click()
        time.sleep(1)
        currenturl = self.browser.current_url

        self.assertEqual(currenturl, self.live_server_url + '/cv')

        #User is not logged in so goes to Log in page
        self.browser.find_element_by_link_text('Log in').click()
        time.sleep(1)
        currenturl = self.browser.current_url

        self.assertEqual(currenturl, self.live_server_url + '/accounts/login/')

        #User goes back to CV page
        self.browser.find_element_by_link_text('CV').click()
        time.sleep(1)
        currenturl = self.browser.current_url

        self.assertEqual(currenturl, self.live_server_url + '/cv')
Ejemplo n.º 43
0
username.send_keys(q)
password.send_keys(password)
browser.find_element_by_id("login_button").click()

sea_url = 'https://y.qq.com/portal/search.html#page=1&searchid=1&remoteplace=txt.yqq.top&t=song&w='
time.sleep(3)
fild = []
for x in name:
    try:
        url = sea_url + x.encode('utf-8')
        browser.get(url)
        time.sleep(1)
        actions = ActionChains(browser)
        actions.click(
            browser.find_element_by_css_selector(
                "i.list_menu__icon_add")).perform()
        time.sleep(1)
        lists = browser.find_elements_by_css_selector("li.operate_menu__item")
        lists[1].click()
        time.sleep(1)
    except:
        try:
            browser.find_element_by_css_selector("a.popup__close").click()
        except:
            pass
        else:
            pass
        fild.append(x)
        print x.encode('utf-8')
    else:
Ejemplo n.º 44
0
Time2Go = False

if targetstart < datetime.datetime.now() or ActWait == False:
    SkipAntiCaptcha = True
else:
    SkipAntiCaptcha = False

if SkipAntiCaptcha == True:
    print 'skipping anti captcha'
else:
    browser.get('http://login.wordpress.org/register')
    time.sleep(2)
    fktype(browser.find_element_by_xpath('//*[@id="user_login"]'), 'BLAHBLAH',
           'Wordpress login')
    fktype(browser.find_element_by_xpath('//*[@id="user_email"]'),
           '[email protected]', 'Wordpress email')

    action.reset_actions()
    Wordpress_confirm = browser.find_element_by_xpath('//*[@id="wp-submit"]')
    action.click(Wordpress_confirm).perform()

delay_until(targetstart)

browser.get('https://www.supremenewyork.com/shop/new')
print color.BOLD + color.GREEN + 'WAITING FOR ITEM SELECTION' + color.END
wait = WebDriverWait(browser, 10)
wait.until(EC.url_changes("https://www.supremenewyork.com/shop/new"))
time.sleep(0.25)
wait.until(EC.url_changes(browser.current_url))
Ejemplo n.º 45
0
                f"(//div[contains(@class, 'section-carousel')]//div[contains(@class, 'section-carousel')])[last()]/div[{i}]"
            )
            driver.execute_script("arguments[0].click()", result)
            time.sleep(3)

            html = driver.page_source
            respObj = Selector(text=html)

            name = respObj.xpath("//h1/span/text()").get()

            phone = None
            if respObj.xpath("//button[@aria-label='Copy phone number']"):
                phoneElem = driver.find_element_by_xpath(
                    "//button[@aria-label='Copy phone number']")
                hover = ActionChains(driver).move_to_element(phoneElem)
                hover.click().perform()
                time.sleep(1)
                phone = pc.paste()

            website = None
            if respObj.xpath("//button[@aria-label='Copy website']"):
                websiteElem = driver.find_element_by_xpath(
                    "//button[@aria-label='Copy website']")
                hover = ActionChains(driver).move_to_element(websiteElem)
                hover.click().perform()
                time.sleep(1)
                website = pc.paste()

            address = None
            if respObj.xpath("//button[@aria-label='Copy address']"):
                addressElem = driver.find_element_by_xpath(
Ejemplo n.º 46
0
time.sleep(5)
later_btn = driver.find_element_by_class_name("HoLwm")

later_btn.click()


driver.get("https://www.instagram.com/geon__after")

time.sleep(3)

first_post_xpath = '//*[@id="react-root"]/section/main/div/div[2]/article/div[1]/div/div[1]/div[1]/a/div[1]/div[2]'
first_post = driver.find_element_by_class_name("eLAPa")



actionchains.click(first_post).perform()
driver.implicitly_wait(5) 
driver.get(driver.current_url)
##driver.refresh()


##post_like_btn_xpath='/html/body/div[4]/div[2]/div/article/div[2]/section[1]/span[1]'
##post_like_btn=driver.find_element_by_xpath(post_like_btn_xpath)

print(driver.page_source)

post_like_btn = driver.find_element_by_class_name("fr66n")
driver.find_element_by_class_name("fr66n").click()
##print(post_like_btn.get_attribute('innerHTML'))
##actionchains.click(post_like_btn).perform()
Ejemplo n.º 47
0
wd = proxy.wd

atexit.register(wd.quit)

wd.implicitly_wait(30)

wd.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&"
       "rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&"
       "ltmpl=default&ltmplcache=2&emr=1&osid=1")

login_el = wd.find_element_by_id("identifierId")

enter_username = ActionChains(wd)
enter_username.move_to_element(login_el)
enter_username.click(login_el)
enter_username.send_keys("{}\n".format(u))
enter_username.perform()

WebDriverWait(wd, 30).until(EC.element_to_be_clickable((By.ID, "password")))

pass_el = wd.find_element_by_id("password")

enter_password = ActionChains(wd)
enter_password.move_to_element(pass_el)
enter_password.click(pass_el)
enter_password.send_keys("{}\n".format(p))
enter_password.perform()

wd.find_element_by_xpath("//span[.='open me']").click()
wd.find_element_by_partial_link_text("127.0.0.1").click()
Ejemplo n.º 48
0
def getBlackboardInfo(username, password):

    # set our username/email variable
    EMAIL = username
    # set our password variable
    PASSWORD = password

    # set our blackboard url
    url = "https://uic.blackboard.com/?new_loc=%2Fultra%2Finstitution-page%2Feffective"

    # we will need a web scraper to do this, since there is no API
    # the scraper we are using is selenium

    # our web driver, this is like our 'browser'
    # we have a selenium hub docker image running
    # it has multiple 'chrome' nodes
    # this web driver will connect to one of those 'chrome' nodes
    driver = webdriver.Remote(command_executor='http://hub:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)

    # in case it takes a while, set our max waiting times
    driver.implicitly_wait(30)
    # fetch the blackboard site
    driver.get(url)

    # find the login button on the page
    loginButton = driver.find_element_by_xpath('/html/body/div[1]/section/div[1]/div/div/div[1]/a')

    # click the login button
    actions = ActionChains(driver)
    actions.move_to_element(loginButton)
    actions.click(loginButton)
    actions.perform()

    # find the username field and fill it in
    usrname = driver.find_element_by_xpath('/html/body/div[2]/form/input[8]')
    usrname.send_keys(EMAIL)

    # find the password field and fill it in
    pword = driver.find_element_by_xpath('/html/body/div[2]/form/input[9]')
    pword.send_keys(PASSWORD)

    # send enter, to basically attempt to login
    pword.send_keys(Keys.RETURN)

    # now navigate to our stream
    driver.get('https://uic.blackboard.com/ultra/stream')

    # this can be incredibly slow
    # so use a hard sleep to wait for it to load
    time.sleep(4)
    
     # we will use beautiful soup to parse the webpage that we receive
    soup = BeautifulSoup(driver.page_source, 'html.parser')

    # find our streams
    streams = soup.find(id="activity-stream").findAll('div', recursive=False)

    # get the stream that we want, which is the 'Recent' stream
    # we use this stream because it basically has everything
    notes = streams[0].find('h2')
    for stream in streams:
        if stream.find('h2').text == "Recent":
            notes = stream

    # store each bit of stream info here
    info = []
    for note in notes.findAll('div'):
        info.append(note.text)

    # store all our stream infos as a list here
    blackboardInfo = []
    #learned how to filter out empty strings from geeksforgeeks.org
    for item in info:
        note = {}
        # clean out empty strings and spaces
        # because data is messy, and empty strings occur frequently
        note["content"] = list(filter(None, item.strip().splitlines()))
        if(len(note["content"]) > 2):
            blackboardInfo.append(note)
    
    # make sure to quit our driver
    driver.quit()

    # return our info
    return blackboardInfo
Ejemplo n.º 49
0
def execute_app():
    start_time = time.time()
    companies = load_symbols()
    # Start interacting with the browser
    driver.maximize_window()
    driver.get(login_url)
    print("Please log in")
    print("Go to Company View->Research")
    print("Do a sample search")
    print("Then press Enter")
    foo = input()
    # Manually login with CWL
    print("Logged in")
    assert "Thomson One" in driver.title  # sanity check
    print("Ready to start jobs")

    companies = ['AAPL-US', 'ADBE-US']  # DEBUG
    total_count = len(companies)
    for i, company in enumerate(companies):
        print("{} Processing {}".format(datetime.datetime.now(), company))
        print("Overal Elapsed Time: {:.1f} seconds".format(time.time() -
                                                           start_time))
        print("Overal Progress: {}/{}={:.2f}%".format(i, total_count,
                                                      i / total_count * 100))
        # for f in ["frameWinF7", "PCPWinF6", "PCPWinF7", "frameWinF6"]:
        try:
            # print("try F7")
            driver.switch_to.default_content()
            driver.switch_to.frame("frameWinF7")
            driver.switch_to.frame("PCPWinF7")
            # print("F7!")
        except:
            try:
                # print("try F6")
                driver.switch_to.default_content()
                driver.switch_to.frame("frameWinF6")
                driver.switch_to.frame("PCPWinF6")
                # print("F6!")
            except:
                print("Bad, can't switch into any frame")
                exit()
        try:
            print("trying to find trackInput")
            trackinput = driver.find_element_by_id("trackInput")
            trackinput.clear()
            trackinput.send_keys(company)
            print("Entered company name {}".format(company))
            # time.sleep(1)

            go = driver.find_element_by_id("go")
            go.send_keys(u'\ue007')
            print("Go!")
            time.sleep(5)  #TODO

            t = time.time()
            n = len(contributors)
            for j, contributor in enumerate(contributors):
                try:
                    print("Processing {}_{}".format(company, contributor))
                    print(" Elapsed Time: {:.1f} seconds".format(time.time() -
                                                                 t))
                    print(" Progress    : {}/{}={:.1f}%".format(
                        j, n, j / n * 100))
                    print(driver.window_handles)

                    driver.switch_to.default_content()
                    driver.switch_to.frame("frameWinC1-4054-8135")
                    # print("switched to frameWinC1-4054-8135")
                    driver.switch_to.frame("PCPWinC1-4054-8135")  #id =3234
                    # print("switched to frame PCPWinC1-4054-8135")

                    if j == 0:  #only need to set dates once for each company
                        # range = driver.find_element_by_id("ctl00__criteria_dateRange")
                        driver.execute_script(
                            'document.getElementById("ctl00__criteria_dateRange").selectedIndex = 7'
                        )  # Custom
                        # Enter dates
                        driver.execute_script(
                            'document.getElementById("ctl00__criteria__fromDate").value = "01/01/15"'
                        )
                        print("Entered from date")
                        driver.execute_script(
                            'document.getElementById("ctl00__criteria__toDate").value = "01/01/18"'
                        )
                        print("Entererd to date")

                    ctb_input = driver.find_element_by_id(
                        "contributors.searchText")
                    ctb_input.clear()  # delete
                    for k in range(4):
                        ctb_input.send_keys('\b\b\b\b\b\b\b')
                    ctb_input.send_keys(contributor)
                    print("Entered {}".format(contributor))
                    # wait for pop up to show and choose first by default
                    WebDriverWait(driver, timeout).until(
                        EC.presence_of_element_located(
                            (By.CLASS_NAME, "dijitMenuItem")))
                    option = driver.find_element_by_class_name("dijitMenuItem")
                    # Strange offset problem with Dojo combobox
                    h = ActionChains(driver).move_to_element(
                        option).move_by_offset(0, -60)
                    h.click().perform()
                    print("Added contibutor {}".format(contributor))
                    time.sleep(1)

                    # Search
                    bt_search = driver.find_element_by_id(
                        "ctl00__criteria__searchButton")
                    bt_search.send_keys(u'\ue007')
                    print("Clicked search button!")
                    time.sleep(6)  # TODO wait for search result to appear
                    # old_page = driver.find_element_by_id('ctl00__results__resultContainer')
                    # WebDriverWait(driver, timeout).until(EC.staleness_of(old_page))

                    try:
                        driver.execute_script(
                            "document.getElementById('select-all-reports').click();"
                        )
                        print("Search results available")
                        print("Selected all reports!")
                    except Exception as e:
                        print(e)
                        print("No search result")
                        continue  # with next contributor

                    # click View
                    view = driver.find_element_by_xpath(
                        '//*[@title="View Selected"]')
                    view.send_keys(u'\ue007')
                    print("Clicked View!")

                    # New window should open
                    # https://stackoverflow.com/questions/10629815/how-to-switch-to-new-window-in-selenium-for-python
                    WebDriverWait(driver,
                                  timeout).until(EC.number_of_windows_to_be(2))

                    current = driver.current_window_handle
                    print("windows:", driver.window_handles)
                    print("current window is", current)
                    newWindow = [
                        window for window in driver.window_handles
                        if window != current
                    ][0]
                    driver.switch_to.window(newWindow)
                    print("OPEN NEW WINDOW")

                    try:
                        wait = WebDriverWait(driver, timeout)
                        wait.until(
                            EC.frame_to_be_available_and_switch_to_it(
                                (By.NAME, 'content')))
                        # driver.switch_to.frame("content")

                        # Select All Reports
                        driver.execute_script(
                            "document.getElementById('ctl00_ctlTocDisplay_chkToc').click();"
                        )
                        print("Selected all reports 2")
                        # Click view
                        view = driver.find_element_by_name(
                            "ctl00$ctlTocDisplay$btnSubmit")
                        print("Clicked View 2")
                        view.send_keys(u'\ue007')
                        # open up the download dialog
                    except Exception as e:
                        print("Can't switch: {}".format(e))
                        driver.close()
                        driver.switch_to.window(current)
                        continue

                    try:
                        # wait for download dialog to open
                        time.sleep(6)
                        print("Download dialog should have opened")

                        # Use pyautogui to save the pdf file
                        # TODO try pywinauto
                        # https://pywinauto.readthedocs.io/en/latest/HowTo.html#how-to-specify-a-usable-application-instance
                        app = Application().connect(title_re="View Downloads")
                        dlg = app.window(title_re="View Downloads")
                        # dlg.print_control_identifiers()
                        # dlg.move_window(500,100) # fixed position
                        dlg.maximize()
                        print("ready to download")
                        # TODO Pyautogui

                        # conflict need version 0.6.6
                        # https://github.com/asweigart/pyautogui/issues/353

                        # https://sqa.stackexchange.com/questions/31436/how-to-save-a-file-by-clicking-on-a-link-in-python-internet-explorer-windows
                        # https://stackoverflow.com/questions/11449179/how-can-i-close-a-specific-window-using-selenium-webdriver-with-java
                        time.sleep(1)
                        gui.moveTo(
                            save_as_x, save_as_y
                        )  # position of the 'inverse triangle' button
                        gui.click()
                        gui.press('a')  # save as
                        gui.click()
                        # Default file name format: SYMBOL_CONTRIBUTOR
                        gui.typewrite(company + "_" + contributor)
                        time.sleep(1)
                        gui.press('enter')
                        print("started download")

                        try:
                            # this is intended to close the loading window
                            close_unwanted_windows(driver, current)
                            # the new window for reports closes automatically
                        except Exception as e:
                            print("error with close")
                            print(e)
                        print("Switching back to main search page")
                        # this hangs but is a required call somehow
                        driver.switch_to.window(current)
                        print("Gone back to main search page")
                    except Exception as e:
                        print(e)
                        print("Ignore this timeout exception")
                except Exception as e:
                    print("Exception: {}_{}".format(company, contributor))
                    print(e)

            print("PROCESSED {}".format(company))
            print("---------------------------------")
            success.append(company)

            driver.switch_to.default_content()
        except Exception as e:
            print(e)
Ejemplo n.º 50
0
def DM(username, password, person, dm):
    path = "C:\\Users\\My Hot PC\\Desktop\\Selenium\\chromedriver.exe"
    driver = webdriver.Chrome(path)

    driver.get("https://www.instagram.com/")
    enter_username = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.NAME, 'username')))
    enter_username.send_keys(username)

    enter_password = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.NAME, 'password')))
    enter_password.send_keys(password)
    enter_password.send_keys(Keys.RETURN)
    time.sleep(random.randint(1, 4))

    try:
        not_now = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((By.CLASS_NAME, 'mt3GC')))
        a = not_now.find_elements_by_tag_name("button")[1]
        actions = ActionChains(driver)
        actions.click(a)
        actions.perform()
    except:
        pass
    finally:
        inbox = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((By.CLASS_NAME, 'xWeGp')))
        actions = ActionChains(driver)
        actions.click(inbox)
        actions.perform()
        time.sleep(random.randint(1, 4))

    try:
        not_now = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((By.CLASS_NAME, 'mt3GC')))
        a = not_now.find_elements_by_tag_name("button")[1]
        actions = ActionChains(driver)
        actions.click(a)
        actions.perform()
    except:
        pass
    finally:
        new_message = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((By.CLASS_NAME, 'QBdPU')))
        actions = ActionChains(driver)
        actions.click(new_message)
        actions.perform()

    enter_person_name = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.NAME, 'queryBox')))
    enter_person_name.send_keys(person)

    time.sleep(random.randint(1, 4))

    select_person = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.CLASS_NAME, 'dCJp8')))
    actions1 = ActionChains(driver)
    actions1.click(select_person)
    actions1.perform()

    next_button = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.CLASS_NAME, 'rIacr')))
    actions1 = ActionChains(driver)
    actions1.click(next_button)
    actions1.perform()

    messagebox = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.TAG_NAME, 'textarea')))
    messagebox.send_keys(dm)
    time.sleep(random.randint(1, 3))
    messagebox.send_keys(Keys.RETURN)
Ejemplo n.º 51
0
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
from bs4 import BeautifulSoup as BS

street = input()

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.delivery-club.ru/moscow')

page = driver.find_element_by_class_name('wrap')
address = page.find_element_by_class_name('address-input')

actions = ActionChains(driver)
actions.click(address)
actions.perform()

element = driver.find_element_by_class_name('address-suggest__search-input')
element.send_keys(street)
driver.implicitly_wait(5)
element.send_keys(Keys.RETURN)

soup = BS(driver.page_source, 'lxml')
page = soup.find('div', {'class': 'wrap-max-width vendor-list__wrap'})
content = page.find('ul', {'class': 'vendor-list__ul'})

for item in content.find_all('li', {'class': 'vendor-item'}):
    print('')

    title = item_content.find('span', {'class': 'vendor-item__title'})
Ejemplo n.º 52
0
 def click_with_coordinates(self, element_id, x, y):
     el = self._instance.find_element_by_id(element_id)
     action = ActionChains(self._instance)
     action.move_to_element_with_offset(el, x, y)
     action.click()
     action.perform()
Ejemplo n.º 53
0
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# Specify browser driver location
driver_location = "chromedriver.exe"

# Connect browser driver
driver = webdriver.Chrome(driver_location)

# Will put driver to wait mode for 5 seconds
driver.implicitly_wait(5)

# get() command will open browser and visit page given in ()
driver.get('https://particle-clicker.web.cern.ch/')

click_object = driver.find_element_by_id('detector-events')

actions = ActionChains(driver)
actions.click(click_object)
count = 0

for i in range(500):
    actions.perform()
    count += 1
    print(count)
Ejemplo n.º 54
0
 def double_click_element_at_position(self, element, x, y):
     actions = ActionChains(self._driver)
     actions.move_to_element_with_offset(element, x, y)
     actions.click()
     actions.click()
     actions.perform()
Ejemplo n.º 55
0
 def click(self):
     action = ActionChains(self.context)
     action.move_by_offset(self.element_coordinates[0],
                           self.element_coordinates[1])
     action.click()
     action.perform()
Ejemplo n.º 56
0
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get('https://orteil.dashnet.org/cookieclicker/')

driver.implicitly_wait(5)

cookie = driver.find_element_by_id("bigCookie")
cookieCount = driver.find_element_by_id("cookies")
items = [
    driver.find_element_by_id("productPrice" + str(i))
    for i in range(1, -1, -1)
]

actions = ActionChains(driver)
actions.click(cookie)

for i in range(5000):
    actions.perform()
    count = int(cookieCount.text.split(" ")[0])
    for item in items:
        value = int(item.text)
        if value <= count:
            upgrade_actions = ActionChains(driver)
            upgrade_actions.move_to_element(item)
            upgrade_actions.click()
            upgrade_actions.perform()
Ejemplo n.º 57
0
    def check_go_to_link(self,
                         this_url,
                         link_parent_selector,
                         link_text,
                         url_name=None,
                         kwargs=None,
                         expected_regex=None,
                         partial=False,
                         href_itself=None,
                         sleep_time=None):
        """
        Допоміжна функція для функц.тесту. Викликається в циклі for
        для кожного лінка на сторінці.
        Перевіряє, чи користувач може перейти по лінку, заданому url_name
        з текстом "link_text"
        :param this_url: сторінка що тестується
        :param link_parent_selector: CSS-селектор елемента з лінками
        :param link_text: видимий текст лінка
        :param url_name: назва, з якої ф-цією reverse отримується url переходу
        :param kwargs: евентуальні параметри url
        :param expected_regex: очікуваний url - задавати при переадресації, бо тоді він інакший, ніж reverse(url_name)
        :param partial: часткове чи повне співпадіння тексту лінка
        :param href_itself: атрибут href, за яким йде пошук, якщо не задано link_text
        :param sleep_time: час очікування вкінці на завершення процесів на відвіданій сторінці
        :return:
        """
        self.browser.get('%s%s' % (self.server_url, this_url))
        # print(link_parent_selector, link_text, expected_regex)
        #
        # TODO-виловити помилку при очікуванні на сторінку "Картотека" головної сторінки.
        # Помилка виникає часом.
        # Trace:
        # selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: xhrErrorAlert:
        #  xhr.status=0
        #  xhr.statusText=error
        #  xhr.responseText={"server_response": {"selRowIndex": 0, "model": null, "id": null}}
        #
        # TODO-2015 12 31 помилка xhrError
        # selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: xhrErrorAlert:
        #  xhr.status=0
        #  xhr.statusText=error
        #  xhr.responseText=
        # <super: <class 'WebDriverException'>, <UnexpectedAlertPresentException object>>

        if url_name and not expected_regex:
            expected_regex = reverse(url_name, kwargs=kwargs)
        expected_regex = expected_regex.lstrip('^')

        # print('link_parent_selector =', link_parent_selector)
        # print('link_text =', link_text)

        parent = self.browser.find_element_by_css_selector(
            link_parent_selector)

        if link_text:
            if partial:
                href = parent.find_element_by_partial_link_text(link_text)
            else:
                href = parent.find_element_by_link_text(link_text)
        elif href_itself:
            href = parent.find_element_by_xpath("//a[contains(@href,'%s')]" %
                                                href_itself)
        else:
            href = None

        # print('href.location_once_scrolled_into_view =', href.location_once_scrolled_into_view)

        try:
            actions = ActionChains(self.browser)
            actions.move_to_element(href)
            actions.click(href)
            actions.perform()
        except Exception as exception:
            print(
                'Attention: Exception in actions caused probably by too long searched link text:'
            )
            print(link_text)
            print(exception)
            return
        passing_url = self.browser.current_url  # url після переходу

        # print('link_parent_selector =', link_parent_selector)
        # print('link_text =', link_text)
        # print('href =', href)
        # print('url_name =', url_name)
        # print('kwargs =', kwargs)
        # print('passing_url =', passing_url)
        # print('expected_regex =', expected_regex)

        self.assertRegex(passing_url, expected_regex)
        if sleep_time:
            sleep(sleep_time
                  )  # чекаємо на завершення обміну даними на деяких сторінках
driver.get('https://www.autocareparts.com/')

# 2. Hover over Shop by Brand button
action.move_to_element(driver.find_element(*SHOP_BY_BRAND)).perform()
# 3. Hover over Numbers button
action.move_to_element(driver.find_element(*NUMBERS)).perform()
# 4. Hover over One shot button
action.move_to_element(driver.find_element(*ONE_SHOT)).perform()
# 5. Click on One shot button
driver.find_element(*ONE_SHOT).click()
# 6. Click on One shot picture
target = wait.until(EC.element_to_be_clickable(ONE_SHOT_PIC))
actions = ActionChains(driver)
actions.move_to_element(target)
sleep(2)
actions.click(on_element=target)
actions.perform()
# 7. Click on Add to Cart button
driver.find_element(*ADD_TO_CART).click()
# 8. Click and close shopping cart
target = wait.until(EC.element_to_be_clickable(CLOSE_SHOPPING_CART))
actions = ActionChains(driver)
actions.move_to_element(target)
sleep(2)
actions.click(on_element=target)
actions.perform()
# 9. Verify "1" is in the cart
text = '1'
searhed_word = (text).lower()
actual_word = (wait.until(
    EC.presence_of_element_located(QUANTITY_IN_CART)).text).lower()
Ejemplo n.º 59
0
    def get_company_info(self, url):
        '''
        Извлекает информацию о каждой компании и людях, которые там работают и помещает информацию в словарь 'self.info'
        '''

        time.sleep(3)

        self.driver.get(url)

        try:
            show_number = WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located((
                    By.XPATH,
                    '//*[@id="react-toplevel"]/div/main/div/div/div[1]/div[1]/div[1]/div/div/div[2]/div[1]/ul/div[1]/li[2]/div[1]/span[2]/span'
                )))
            action = ActionChains(self.driver)
            action.click(show_number)
            action.perform()
        except:
            pass

        soup = BeautifulSoup(self.driver.page_source, 'lxml')

        self.info[url]['company_info'] = {}

        try:
            name = soup.find('div', {
                'class': 'Profile__Name listing-name'
            }).get_text()
            self.info[url]['company_info']['Полное имя компании'] = name
        except:
            try:
                name = soup.find('div', {
                    'class':
                    'Profile__Name Profile__Name--short listing-name'
                }).get_text()
                self.info[url]['company_info']['Полное имя компании'] = name
            except:
                pass

        try:
            for i in soup.find('ul', {
                    'class': 'fa-ul ContactInformation__List'
            }).find_all('li'):
                number = i.get_text().split()[-1][:-1]
                break
            self.info[url]['company_info']['Номер'] = number
        except:
            pass

        try:
            phone_number = soup.find(
                'a', {'class': 'listing-phone'})['href'].replace('tel:', '')
            self.info[url]['company_info'][
                'Номер телефона компании'] = phone_number
        except:
            pass

        try:
            address = soup.find('a', {
                'class': 'SearchResult__Link'
            }).get_text()
            self.info[url]['company_info']['Адрес'] = address
        except:
            pass

        try:
            site = soup.find('a', {'class': 'listing-website-url'}).get_text()
            self.info[url]['company_info']['Сайт'] = site
        except:
            pass

        try:
            mail = soup.find('a', {'class': 'listing-email'}).get_text()
            self.info[url]['company_info']['email'] = mail
        except:
            pass

        try:
            for tr in soup.find(
                    'table', {
                        'class': 'Financials__Table table table-condensed'
                    }).find_all('tr'):

                try:
                    if tr.th.get_text() == 'Liikevaihto (tuhatta euroa)':
                        for td in tr.find_all('td'):
                            income = td.get_text()
                        self.info[url]['company_info']['Оборот'] = income
                except:
                    pass

                try:
                    if tr.th.get_text() == 'Henkilöstö':
                        for td in tr.find_all('td'):
                            employ = td.get_text()
                        self.info[url]['company_info'][
                            'Количество рабочих'] = employ
                except:
                    pass
        except:
            pass

        try:
            bosses = []
            for bos in soup.find_all(
                    'li', {'class': 'DecisionPerson DecisionPerson--prh'}):
                bosses.append(bos.get_text()[1:])
            self.info[url]['company_info']['Учредители'] = bosses
        except:
            pass

        try:
            persons_url = []
            for person_url in soup.find_all(
                    'a', {'class': 'AdditionalContacts__Name'}):
                persons_url.append(
                    self.root_url.replace('/search', '') + person_url['href'])
            self.info[url]['company_info']['persons_url'] = persons_url
        except:
            pass

        time.sleep(0.5)

        try:
            for person_url in self.info[url]['company_info']['persons_url']:

                self.driver.get(person_url)
                self.info[url]['company_info'][person_url] = {}

                time.sleep(1)

                try:
                    show_number = WebDriverWait(self.driver, 5).until(
                        EC.presence_of_element_located((
                            By.XPATH,
                            '//*[@id="react-toplevel"]/div/main/div/div/div[1]/div[1]/div/div/ul/div[1]/li/div[1]/span[2]'
                        )))
                    action = ActionChains(self.driver)
                    action.click(show_number)
                    action.perform()
                except:
                    pass

                soup = BeautifulSoup(self.driver.page_source, 'lxml')

                try:
                    name = soup.find('div', {
                        'class':
                        'Profile__Name Profile__Name--short listing-name'
                    }).get_text()
                    self.info[url]['company_info'][person_url][
                        'Имя работника'] = name
                except:
                    try:
                        name = soup.find('div', {
                            'class': 'Profile__Name listing-name'
                        }).get_text()
                        self.info[url]['company_info'][person_url][
                            'Имя работника'] = name
                    except:
                        pass

                try:
                    position = soup.find('div', {
                        'class': 'Profile__Title'
                    }).get_text()
                    self.info[url]['company_info'][person_url][
                        'Должность'] = position
                except:
                    pass

                try:
                    phone_number = soup.find('div', {
                        'class': 'PhoneNumber__Unhidden'
                    }).find('a')['href'].replace('tel:', '')
                    self.info[url]['company_info'][person_url][
                        'Номер работника'] = phone_number
                except:
                    pass

                try:
                    email = soup.find('a', {
                        'class': 'listing-email'
                    }).get_text()
                    self.info[url]['company_info'][person_url][
                        'email работника'] = email
                except:
                    pass
        except:
            pass
Ejemplo n.º 60
0
    def test_recents(self):
        self.driver.get("http://localhost:8888/lab/")
        self.driver.implicitly_wait(40)
        # WebDriverWait(self.driver, 100)
        tests_folder = self.driver.find_element(
            By.XPATH, "//span[contains(text(),'tests')]")
        self.driver.implicitly_wait(30)
        actions = ActionChains(self.driver)
        actions.move_to_element(tests_folder)
        # print('before wait')

        #self.driver.implicitly_wait(10)

        actions.double_click(tests_folder).perform()
        self.driver.implicitly_wait(30)

        test_file = self.driver.find_element(
            By.XPATH, "//span[contains(text(),'test_file.rtf')]")
        self.driver.implicitly_wait(30)
        actions = ActionChains(self.driver)
        actions.double_click(test_file).perform()

        self.driver.implicitly_wait(30)
        file_elem = self.driver.find_element(
            By.XPATH, "/html/body/div/div[2]/div[2]/ul/li[1]")
        actions = ActionChains(self.driver)
        self.driver.implicitly_wait(30)
        actions.click(file_elem).perform()

        recents = self.driver.find_element(
            By.XPATH, "//div[contains(text(),'Recents')]")
        actions = ActionChains(self.driver)
        self.driver.implicitly_wait(30)
        actions.click(recents).perform()
        self.driver.implicitly_wait(30)

        folder_recent = self.driver.find_element(
            By.XPATH, "//div[contains(text(),'tmp/jupyterlab-recents/tests')]")
        assert folder_recent.text == "/tmp/jupyterlab-recents/tests"

        file_recent = self.driver.find_element(
            By.XPATH,
            "//div[contains(text(),'tmp/jupyterlab-recents/tests/test_file.rtf')]"
        )
        assert file_recent.text == "/tmp/jupyterlab-recents/tests/test_file.rtf"

        # file_elem = self.driver.find_element(By.XPATH, "/html/body/div/div[2]/div[2]/ul/li[1]")
        # actions.click(file_elem).perform()
        # self.driver.implicitly_wait(30)
        #recents = self.driver.find_element(By.XPATH, "//div[contains(text(),'Recents')]")
        #recents = self.driver.find_element(By.XPATH, "/html/body/div[2]/ul/li[6]")
        # recents = self.driver.find_element_by_css_selector("li.lm-Menu-item:nth-child(7)")
        # actions = ActionChains(self.driver)
        # actions.click(recents).perform()
        clear_recents = self.driver.find_element(
            By.XPATH, "//div[contains(text(),'Clear Recents')]")
        actions = ActionChains(self.driver)
        self.driver.implicitly_wait(30)
        actions.click(clear_recents).perform()
        self.driver.implicitly_wait(30)
        # actions.click(file_elem).perform()
        # actions.click(recents).perform()
        # cleared_txt = self.driver.find_element(By.XPATH, "/html/body/div[3]/ul/li")
        # assert cleared_txt.text == "Clear Recents"
        # WebDriverWait(self.driver, 100)

        #home_folder = self.driver.find_element(By.XPATH, "/html/body/div[2]/div[3]/div[2]/div[1]/div[5]/div[2]/span[1]")
        #home_folder = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[1]/div[6]/div[2]/span[1]")
        home_folder = self.driver.find_element_by_css_selector(
            ".jp-BreadCrumbs-home")
        #home_folder = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[1]/div[6]/div[2]/span[1]/svg")
        actions = ActionChains(self.driver)
        self.driver.implicitly_wait(30)
        actions.click(home_folder).perform()