Exemplo n.º 1
1
 def choose_page(self, key):
     '''分页操作'''
     pange_number = 15  # 每页展示的数据,默认是15条
     driver = self.conf.driver
     driver.implicitly_wait(10)
     # 获取分页的数量
     xpath = LC.COMMON[key]
     # 页面总数所在的xpath的路径值
     totle = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, xpath))).text
     totles = int(totle)
     print('totles  is :', totles)
     # 计算页数
     pages = int(totles / pange_number)
     sum0 = driver.find_elements_by_xpath(xpath="//tr[@class='ng-scope']")
     sum = len(sum0)
     time.sleep(1)
     i = 0
     for i in range(0, pages):
         # import pdb
         # pdb.set_trace()
         xpath1 = '//*[@id="main-container"]/div[1]/div[2]/div[2]/div/div/div[4]/ul[1]/li[8]/a'
         ele2 = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath(xpath=xpath1))
         ele2.click()
         time.sleep(0.5)
         count0 = driver.find_elements_by_xpath(xpath="//tr[@class='ng-scope']")
         count = len(count0)
         sum = sum + count
         time.sleep(0.5)
         print('sum  is :', sum)
         i = i + 1
     time.sleep(0.5)
     assert sum == totles, "列表总数不正确,分页校验失败"
     print("总条数:%s,页数:%s" % (totles,pages))
     print('列表总数正确,分页校验成功')
Exemplo n.º 2
0
 def hide_and_get(self):
     # hide current menu and get it again
     menu = WebDriverWait(self.driver, 30, 0.1).until(
         lambda d: d.find_element_by_css_selector(self.DROP_MENU_SELECT)
     )
     menu.click()
     menu.click()
Exemplo n.º 3
0
    def test_channelAnimatorBoundaryAnimation(self):
        driver = self.driver 

        # Open a test image so we have something to animate
        Util.load_image( self, driver, "Default")

        # Find and record the last valid value of the animation
        self._getLastValue( driver, "Channel" )
        lastChannelValue = self._getCurrentValue( driver, "Channel" )

        # Find and click the lower spin box
        lowerBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelLowerBoundSpin']/input")))
        driver.execute_script( "arguments[0].scrollIntoView(true);", lowerBoundText)
        lowerBoundText.click()

        # Change the lower bound value
        lowerBoundValue = Util._changeElementText(self, driver, lowerBoundText, 1)

        # Find and click the upper spin box
        upperBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelUpperBoundSpin']/input")))
        driver.execute_script( "arguments[0].scrollIntoView(true);", upperBoundText)
        upperBoundText.click()

        # Change the upper bound value 
        upperBoundValue = Util._changeElementText( self, driver, upperBoundText, int(lastChannelValue)-1)

        # Allow test image to animate for 2 seconds
        self._animateForward( driver, "Channel" )
        time.sleep(2)

        # Check that the lower and upper bound values did not change during animation
        lowerBound = lowerBoundText.get_attribute("value")
        upperBound = upperBoundText.get_attribute("value")
        self.assertEqual( int(lowerBound), int(lowerBoundValue), "Lower bound channel value changed during animation")
        self.assertEqual( int(upperBound), int(upperBoundValue), "Upper bound channel value changed during animation")
Exemplo n.º 4
0
def upload(driver, path):
    elem = WebDriverWait(driver, 30).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, '#cx-detail-pane input'))
    )
    elem.click()
    print('Entering upload form ...')

    elem = WebDriverWait(driver, 30).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, '#cx-dev-upload-form input'))
    )
    print('...')

    driver.execute_script(
        '(function() {'
        'var input = document.querySelector("#cx-dev-upload-form input");'
        'input.style.visibility="visible";'
        'input.style.position = "initial";'
        'input.style.height = "initial";'
        '})();'
    )
    elem.send_keys(path)
    elem = driver.find_element_by_id('upload-btn')
    elem.click()
    print('Uploading %s ...' % path)

    WebDriverWait(driver, 300).until(lambda x: x.title[-len(EDIT_TITLE):] == EDIT_TITLE)
    print('...')
Exemplo n.º 5
0
def get_browser(username, password):
    """Get an instance of a firefox browser"""

    browser = webdriver.Firefox()
    browser.set_window_size(1020, 800)

    # set username
    browser.get('https://www.cgd.pt')
    elem = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, 'input_cx1'))
    )
    elem.send_keys(username + Keys.ENTER)

    # close warnings
    elem = WebDriverWait(browser, 10).until(
        EC.element_to_be_clickable((By.XPATH, '//*[@title="Fechar Aviso"]'))
    )
    elem.click()

    # add password
    elem = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, 'passwordInput'))
    )
    elem.send_keys(password + Keys.ENTER)

    # close warnings
    elem = WebDriverWait(browser, 10).until(
        EC.element_to_be_clickable((By.CLASS_NAME, 'botao_ok'))
    )
    elem.click()

    return browser
Exemplo n.º 6
0
    def delete_workspace(self):
        #Don't delete the default "Take the Tour" workspace, just close the workspace
        if self.driver.title == "Take the Tour":
            self.driver.close()
            return True

        #Click on the cog icon and then select the delete workspace option
        what = self.get_xpath("cog_icon")
        cog_icon = WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable((By.XPATH, what)))
        cog_icon.click()
        what = self.get_xpath("delete_workspace")
        delete_button = WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable((By.XPATH, what)))
        delete_button.click()

        #If there are no widgets then clicking the delete workspace option will close the workspace so wait a few seconds for it to close and then switch to the open window
        #(TODO: Figure out a better way to wait for the window to close)
        time.sleep(2)
        self.driver.switch_to_window(self.driver.window_handles[-1])

        #The confirmation page will only appear if there are widgets on the workspace so ignore the timeout if the confimration doesn't appear
        what = self.get_xpath("delete_workspace_confirmation")
        wait = WebDriverWait(self.driver, 5)
        try:
            confirmation_window = wait.until(EC.element_to_be_clickable((By.XPATH, what)))
        except TimeoutException, e:
            return True
Exemplo n.º 7
0
    def _get_make_picks_page(self):
        """
        Logs in to mlb beat the streak site
        """
        ## Are we already on it?
        if self.pageTitles['picks'] in self.browser.title:
            return

        ## Else navigate to the login page
        if not self.pageTitles['login'] in self.browser.title:
            self._get_login_page()

        ## If we were already logged in, then now we are on the picks page
        if self.pageTitles['picks'] in self.browser.title:
            return
        
        # Otherwise, we need to login
        login = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.ID, 'login_email')))
        login.send_keys(self.username)
        pword = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.ID, 'login_password')))
        pword.send_keys(self.password)
        submit = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.NAME, 'submit')))
        submit.click()
        time.sleep(3)
        assert self.browser.title == self.pageTitles['picks']
Exemplo n.º 8
0
    def setHostname(self, name, desc):
        driver = self.driver
        hostname=name
        
        #Change to the Settings tab in a Microhard
        settingButtonXpath = "//a[@href='/cgi-bin/webif/system-settings.sh']"
        settingButtonEle = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(settingButtonXpath))
        settingButtonEle.click()
        
        #Change Hostname Field
        hostnameFieldXpath = "//input[@name='hostname']"
        hostanmeFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(hostnameFieldXpath))
        hostanmeFieldElement.clear()
        hostanmeFieldElement.send_keys(hostname)

        fieldXpath = "//input[@name='description']"
        fieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(fieldXpath))
        fieldElement.clear()
        fieldElement.send_keys(desc)
        
        
        #Submit the change, like a commit
        commitFieldXpath = "//a[@href='#'][@id='waitbox']"
        commitFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(commitFieldXpath))
        commitFieldElement.click()
Exemplo n.º 9
0
    def __get_team_selection_dropdown(self, **kwargs):
        """
        kwargs --> None
           team: str | team for which we are selecting the dropdown

        """
        ## Extract variables
        team = kwargs['team']

        ## Typecheck
        assert type(team) == str

        ## Necessary team conversions
        team = self.__convert_team(team)

        ## Make sure the player selection dropdown has been dropped
        self._get_player_selection_dropdown()
        selectTeam = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.ID, 'team-name')))
        selectTeam.click()
        time.sleep(3)

        # click on desired team
        team = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, team)))
        team.click()
        time.sleep(3)
Exemplo n.º 10
0
    def has_claimed_mulligan(self):
        """
        Returns True if the account with self.username and self.password
        has claimed its mulligan, false otherwise
        """
        ## navigate to claim mulligan page
        self._get_make_picks_page()
        more = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, "last"))
            )
        more.click()
        button1 = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, "bam-button-primary"))
            )
        buttons = self.browser.find_elements_by_class_name('bam-button-primary')
        buttons[3].click()

        ## Check if we've claimed the mulligan
        mulOption = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, "mulligan-list")) 
            )
        mulOption.click()
        try:
            claimMul = WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, 'claim-mulligan-btn')))
        except TimeoutException:
            return True

        return False
Exemplo n.º 11
0
    def test_check_job_details_page(self):
        driver=self.driver
	self.mine_job()
        job_id=self.submit_job()
        self.assertTrue(self.wait_job_end(job_id))
        self.open_job_page(job_id)
        recipeset_id=self.get_recipe_set_id_from_openning_job_page()
        recipe_id=self.get_recipe_id_from_openning_job_page()
        driver.find_element_by_xpath("//a[@class='btn results-tab']").click()
        driver.find_element_by_xpath("//a[@class='btn hide-results-tab']").click()
        driver.find_element_by_xpath("//button[@class='btn']").click()
        driver.find_element_by_xpath("//button[@class='btn']").click()
        #update whiteboard
        driver.find_element_by_xpath("//a[@class='list']").click()
        driver.find_element_by_id("whiteboard").send_keys("Automation-test")
        driver.find_element_by_xpath("//button[@type='submit']").click()
        #update Rentention Tag
        driver.refresh()
        table=WebDriverSelect(driver.find_element_by_id("job_retentiontag"))
        table.select_by_index(7)
        element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='ui-dialog-buttonset']/button[1]")))
        element.click()
        driver.refresh()
        table=WebDriverSelect(driver.find_element_by_id("job_retentiontag"))
        table.select_by_index(2)
        element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='ui-dialog-buttonset']/button[1]")))
        element.click()
        #Check kickstart is avaiable
        driver.refresh()
        driver.find_element_by_xpath("//a[contains(@href,'kickstart')]").click()
        self.assertIn("%post",driver.page_source)
Exemplo n.º 12
0
	def test_edytujF(self):
		driver = self.driver
		# filtruje po FV
		self.driver.get('http://printmanager.local/index.php/invoices/index/1/2')
		EditBtn = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(".//*[@id='search_by']/table/tbody/tr[1]/td[2]/a/span"))
		EditBtn.click()
		print "---kliknieto edytuj prace"
Exemplo n.º 13
0
    def test_create_quick_new_proposal_for_issue(self):
        self.login(self.u1)
        url = self.full_url(self.community.get_absolute_url())
        self.selenium.get(url)
        self.selenium.find_element_by_xpath('//a[@href="{}main/"]'.format(
            self.community.get_absolute_url())
        ).click()

        # Add a quick issue to the meeting
        self.selenium.find_element_by_xpath(
            '//input[@type="text"]').send_keys("Building a new road")
        self.selenium.find_element_by_xpath('//button[@id="quick-issue-add"]').click()

        # Add a quick proposal to the issue
        button = WebDriverWait(self.selenium, 10).until(
            ec.presence_of_element_located((
                By.LINK_TEXT, 'Building a new road')))
        button.click()
        # self.selenium.find_element_by_link_text("Building a new road").click()
        self.selenium.find_element_by_id("quick-proposal-title").send_keys("New Proposal")
        self.selenium.find_element_by_id("quick-proposal-add").click()

        # Test: If there is a line with text "New Proposal", Its OK.
        time.sleep(0.6)
        self.assertTrue(self.is_element_present(By.XPATH, "//* [contains(text(), 'New Proposal')]"))
Exemplo n.º 14
0
def main():
	# Initialize Browser Settings:
	firefox_settings = get_firefox_settings()
	# Set browser as FireFox with our settings
	driver = webdriver.Firefox(firefox_settings)
	# Open search tool on Frac Focus
	driver.get("http://www.fracfocusdata.org/DisclosureSearch/StandardSearch.aspx")
	found_2000 = False
	num_operators = 835
	for operator_number in range(7,num_operators):
		operator = select_operator(driver,operator_number)
		operator_name = operator.text
		# Click on the operator
		operator.click()
		# Find the search button
		search_button = WebDriverWait(driver,30).until(
							EC.presence_of_element_located((By.ID,"MainContent_btnSearch"))
						)
		# Search for all wells owned by that operator
		search_button.click()
		page_count = driver.find_elements_by_id("MainContent_GridView1_TotalPageLabel")
		if(len(page_count) > 0):
			print(operator_name, page_count[0].text)
			if(int(page_count[0].text) > 99):
				found_2000 = True
		back_button = driver.find_element_by_id("MainContent_btnBackToFilter")
		back_button.click()
	if(found_2000):
		print("Some operator had more than 99 pages... f**k")
Exemplo n.º 15
0
 def export_project(self, project_name):
     """ Clicks the 'export' button. Returns :class:`ExportDialog`. """
     self.search_input = project_name
     element = WebDriverWait(self.browser, TMO).until(
                   lambda browser: browser.find_element_by_link_text(project_name))
     element = element.find_element_by_xpath('../../td[6]/form[2]/button')
     element.click()
	def test_hack_captcha(self):
		driver = self.driver

		# find all the options available for captcha
		optionsXPath = "(//ul//li)"
		options = WebDriverWait(driver, 20).until(lambda driver: driver.find_elements(By.XPATH, optionsXPath))
		print "%d total captcha options found!" % len(options)

		while True:

			# randomly select any option
			# Intentionally chosen the middle one to increase probability of getting email as soon as possible
			selectedOption = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(optionsXPath+"[5]"))
			selectedOption.click()

			try:
				# check if email has been revealed
				emailElementId = "mailto"
				emailElement = WebDriverWait(driver, 2).until(lambda driver: driver.find_element_by_id(emailElementId))

			except TimeoutException:
				# if email isn't revealed, let it try again
				print "Email not found!"
				pass

			else:
				# reveal email
				emailId = emailElement.get_attribute("innerHTML")
				print emailId
				break

			# Find try again button and click, if email hasn't been already revealed
			tryAgainButtonText = "try again"
			tryAgainButton = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_link_text(tryAgainButtonText))
			tryAgainButton.click()
    def test_answer_action(self):
        #self.browser.find_element_by_xpath("(//input[@name='ans'])[2]").click()
        toclick = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_xpath("(//input[@name='ans'])[2]"))	
        toclick.click()
        urgency = self.browser.find_element_by_id("userquestion_urgency")
        urgency.send_keys("7")
        importance = self.browser.find_element_by_id("userquestion_importance")
        importance.send_keys("8")
        self.browser.find_element_by_id("userquestion_changecat").click()
    
        category = self.browser.find_element_by_id("userquestion_category")
        category.send_keys("Strategy")
        self.browser.find_element_by_id("userquestion_changescope").click()
        
        #activescope = self.browser.find_element_by_id("userquestion_activescope")
        #activescope.select_by_visible_text("2 Continental")

        #continent = self.browser.find_element_by_id("userquestion_continent")
        #continent.select_by_visible_text("Africa (AF)")

        #self.browser.find_element_by_id("userquestion_answerreason").clear()
        self.browser.find_element_by_id("userquestion_answerreason").send_keys("the right answer selenium testing")
        #driver.find_element_by_css_selector("input.btn").click()        

        #answer.send_keys("1")

        submit_button = self.browser.find_element_by_css_selector("#submit_record__row input")
        submit_button.click()
	time.sleep(2)

        body = self.browser.find_element_by_tag_name('body')
        self.assertIn('This action', body.text)
Exemplo n.º 18
0
Arquivo: order.py Projeto: hyteer/work
 def click_by_order_id(self,key,id):
     driver = self.conf.wxdriver
     #import pdb;pdb.set_trace()
     xpath = LC.ORDER[key] % str(id)
     el = WebDriverWait(driver, WAIT_TIME).until(EC.element_to_be_clickable((By.XPATH, xpath)))
     time.sleep(1)
     el.click()
Exemplo n.º 19
0
def get_html(url):
    #chromedriver = 'C:/Users/_/AppData/Local/Google/Chrome/Application/chromedriver.exe'
    dcap = dict(DesiredCapabilities.PHANTOMJS)
    dcap["phantomjs.page.settings.userAgent"] = (
        UA
    )
    dcap["takesScreenshot"] = (False)
    try:
        
        options = webdriver.ChromeOptions()
        options.add_argument(UA) 
        browser.get(url + '&ext=' + EXT)
        browser.implicitly_wait(30)
        time.sleep(1)
        #智能等待30秒
        WebDriverWait(browser, 10).until(lambda browser : browser.find_element_by_css_selector('#wxmore > a'))
        element=WebDriverWait(browser, 10).until(lambda browser : browser.find_element_by_css_selector('#wxmore > a'))
        element.click()
        time.sleep(1)
    except selenium.common.exceptions.WebDriverException:
       pass
    try:
        html = browser.page_source
    except Exception as e:
        html = None
        logging.error(e)
    return html
Exemplo n.º 20
0
    def setup_prevalence_chart(self, disease_progression_name, points, timeout=None):
        """Sets up the prevalence chart for the given Disease Progression. Returns the name of the relational function
        that contains the prevalence chart."""
        if timeout is None:
            timeout = self.default_timeout

        self.click_navbar_element('Disease Progression')
        # Once the Disease Progression choices come up, click the desired one
        WebDriverWait(self.selenium, timeout=timeout).until(
            EC.visibility_of_element_located((By.LINK_TEXT, disease_progression_name))
        ).click()

        # Once the latent period, etc. options come up, click to bring up the prevalence chart
        prevalence_options = WebDriverWait(self.selenium, timeout=timeout).until(
            EC.visibility_of_element_located((By.ID, 'id_disease_prevalence'))
        )
        prevalence_name = Select(prevalence_options).first_selected_option.text # remember its name
        prevalence_options.click()

        # Once the prevalence chart comes up, overwrite the old points with the new ones.
        FunctionsPanel(
            WebDriverWait(self.selenium, timeout=timeout).until(
                EC.visibility_of_element_located((By.ID, 'functions_panel'))
            )
        ).set_points(points)

        return prevalence_name
Exemplo n.º 21
0
 def test_it(self):
     browser.get(self.login_url)
     self.assertEqual(browser.title, 'Auth Page')
     browser.find_element_by_id('github').submit()
     self.assertEqual(browser.title,
                      b'Sign in \xc2\xb7 GitHub'.decode('utf-8'))
     form = browser.find_element_by_id('login')
     login = form.find_element_by_name('login')
     login.send_keys(self.login)
     passwd = form.find_element_by_name('password')
     passwd.send_keys(self.password)
     form.find_element_by_name('commit').submit()
     find_title = EC.title_is('Authorize access to your account')
     find_result = EC.presence_of_element_located((By.ID, 'result'))
     WebDriverWait(browser, 2).until(
         lambda driver: find_title(driver) or find_result(driver))
     if browser.title == 'Authorize access to your account':
         btn = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.NAME, 'authorize')))
         btn.click()
         result = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.ID, 'result')))
     else:
         result = browser.find_element_by_id('result')
     self.assertEqual(browser.title, 'Result Page')
     result = browser.find_element_by_id('result').text
     result = json.loads(result)
     self.assertTrue('profile' in result)
     self.assertTrue('credentials' in result)
     self.assertTrue('displayName' in result['profile'])
     self.assertTrue('accounts' in result['profile'])
    def test_answer(self):
        for x in range(0,10):
            #self.browser.find_element_by_xpath("(//input[@name='ans'])[2]").click()
            toclick = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_xpath("(//input[@name='ans'])[2]"))	
            toclick.click()
            urgency = self.browser.find_element_by_id("userquestion_urgency")
            urgency.send_keys("9")
            importance = self.browser.find_element_by_id("userquestion_importance")
            importance.send_keys("10")
            self.browser.find_element_by_id("userquestion_changecat").click()
    
            category = self.browser.find_element_by_id("userquestion_category")
            category.send_keys("Strategy")
            self.browser.find_element_by_id("userquestion_changescope").click()
        
            #activescope = self.browser.find_element_by_id("userquestion_activescope")
            #activescope.select_by_visible_text("2 Continental")

            #continent = self.browser.find_element_by_id("userquestion_continent")
            #continent.select_by_visible_text("Africa (AF)")

            #self.browser.find_element_by_id("userquestion_answerreason").clear()
            self.browser.find_element_by_id("userquestion_answerreason").send_keys("test phase 4 user2")
            #driver.find_element_by_css_selector("input.btn").click()        

            #answer.send_keys("1")

            submit_button = self.browser.find_element_by_css_selector("#submit_record__row input")
            submit_button.click()

            body = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_tag_name('body'))	
            self.assertIn('This question is in progress', body.text)

            self.browser.find_element_by_xpath("//input[@value='Next Question']").click()
Exemplo n.º 23
0
 def test_it(self):
     browser.get(self.login_url)
     self.assertEqual(browser.title, 'Auth Page')
     browser.find_element_by_id('live').submit()
     WebDriverWait(browser, 2).until(
         EC.presence_of_element_located((By.NAME, 'login')))
     self.assertEqual(browser.title,
                      'Sign in to your Microsoft account')
     login = browser.find_element_by_name('login')
     login.send_keys(self.login)
     passwd = browser.find_element_by_name('passwd')
     passwd.send_keys(self.password)
     passwd.submit()
     find_title = EC.title_is('Allow access?')
     find_result = EC.presence_of_element_located((By.ID, 'result'))
     WebDriverWait(browser, 2).until(
         lambda driver: find_title(driver) or find_result(driver))
     if browser.title == 'Allow access?':
         btn = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.NAME, 'submitYes')))
         btn.click()
         result = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.ID, 'result')))
     else:
         result = browser.find_element_by_id('result')
     self.assertEqual(browser.title, 'Result Page')
     result = json.loads(result.text)
     self.assertTrue('profile' in result)
     self.assertTrue('credentials' in result)
     self.assertTrue('displayName' in result['profile'])
     self.assertTrue('accounts' in result['profile'])
Exemplo n.º 24
0
    def test_search_in_google(self):
        driver = self.driver
        driver.get("https://www.google.co.in/")
        self.assertIn("Google", driver.title)
        elem = driver.find_element_by_id("gb_70")
        elem.send_keys()
        elem.send_keys(Keys.RETURN)
        gmailUsername = "******"
        gmailPassword = "******"

        emailFieldID = "Email"
        passFieldID = "Passwd"
        signInFieldXpath = "//input[@id='signIn']"

        emailFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldID))
        passFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(passFieldID))
        signInFieldElement = WebDriverWait(driver, 10).until(
            lambda driver: driver.find_element_by_xpath(signInFieldXpath)
        )

        emailFieldElement.clear()
        emailFieldElement.send_keys(gmailUsername)
        passFieldElement.clear()
        passFieldElement.send_keys(gmailPassword)
        signInFieldElement.click()
Exemplo n.º 25
0
    def wait(parent, timeout=TMO, base_id=None, retries=5):
        """
        Wait for notification. Returns notification message.
        If `retries` <= 0 then we're checking for something we anticipate
        won't be there, so don't worry if it isn't.
        """
        for retry in range(max(retries, 1)):
            time.sleep(0.5)  # Pacing.
            base_id = base_id or 'notify'
            msg_id = base_id + '-msg'
            ok_id  = base_id + '-ok'
            try:
                msg = WebDriverWait(parent.browser, timeout).until(
                          lambda browser: browser.find_element(By.ID, msg_id))
                ok = WebDriverWait(parent.browser, timeout).until(
                          lambda browser: browser.find_element(By.ID, ok_id))
            except WebDriverException as err:
                if retries > 0 or not isinstance(err, TimeoutException):
                    logging.warning('NotifierPage.wait(%s): %r', base_id, err)
            else:
                # Sometimes the 'Ok' button is temporarily obscured.
                try:
                    message = msg.text
                    ok.click()
                    return message
                except WebDriverException as err:
                    logging.warning('NotifierPage.wait(%s): %r', base_id, err)

        if retries > 0 or not isinstance(err, TimeoutException):
            raise err
Exemplo n.º 26
0
    def isPresent(self):
        time.sleep(60)
        elem_projects_1 = self.driver.find_element_by_link_text("Projects")
        elem_projects_1 = WebDriverWait(self.driver, 20).until(lambda driver : driver.find_element_by_link_text("Projects"))
        elem_projects_1.click()
        time.sleep(10)
        self.assertIn(u"Projects", self.driver.title)
        #print self.driver.find_element_by_xpath('//*[@id="snap"]/div/div[5]')
        try:
            snap_finish = WebDriverWait(self.driver, 20).until(lambda d : d.find_elements_by_class_name('processingstep'))
            snap_png=snap_finish[3].get_attribute("style")
        except:
            print '1.catch the snap_finish error, and try again'
            try:
                snap_finish = WebDriverWait(self.driver, 20).until(lambda d : d.find_elements_by_class_name('processingstep'))
                snap_png=snap_finish[3].get_attribute("style")
                pass
            except:
                print '2. catch the snap_finish error, and try again'

                snap_finish = WebDriverWait(self.driver, 20).until(lambda d : d.find_elements_by_class_name('processingstep'))
                snap_png=snap_finish[3].get_attribute("style")
                pass

        print "snap_png is %s " % snap_png
        finish_flag = re.search("step_ok_active", snap_png, re.IGNORECASE)
        print "finish_flag is  %s " % snap_finish
        error_flag = re.search("step_error_active", snap_png, re.IGNORECASE)
        #print "erro_flag is "+ not bool(error_flag)
        if bool(error_flag):
            return False
        else:
            if bool(finish_flag):
                return True
 def execute(self, driver, config):
     #clicking on "Locations"
     driver.find_element_by_xpath("//md-card-content/md-list-item[3]/div/a").click()
     #wait until all locations be there
     element = WebDriverWait(driver, 20).until(
                                           EC.element_to_be_clickable((By.XPATH, '//table'))
                                           )
     
     #create a list of locations
         
     rowCount = len(driver.find_elements(By.XPATH, "//table/tbody/tr"))        
     for i in range(1, rowCount+1):
             object = driver.find_element_by_xpath("//table/tbody/tr["+str(i)+"]/td[2]/a").text
             n = object
             LocationList.append(n)
     print LocationList
     
     # click on the second location
     driver.find_element_by_xpath("//table/tbody/tr[1]/td[2]/a").click()
     #wait till settings will be clickable
     element = WebDriverWait(driver, 20).until(
                                                   EC.element_to_be_clickable((By.XPATH, '//md-sidenav[2]/md-content/ul/li[14]/menu-link/a/span'))
                                                   )
     element.click()
     # deleting location
     driver.find_element_by_xpath("//location-settings-menu/md-menu/button").click()
     element = WebDriverWait(driver, 20).until(
                                                   EC.element_to_be_clickable((By.XPATH, "(//button[@type='button'])[6]"))
                                                   )
     element.click()
     driver.find_element_by_xpath("(//button[@type='button'])[6]").click()
     driver.find_element_by_xpath("(//button[@type='button'])[32]").click()
     driver.find_element_by_xpath("(//button[@type='button'])[34]").click()
     
     
Exemplo n.º 28
0
 def choose_picture(self, key):
     '''选择图片'''
     index = None
     driver = self.conf.driver
     driver.implicitly_wait(10)
     # 点击上传图片的地址
     xpath = LC.COMMON[key]
     ele1 = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath(xpath=xpath))
     time.sleep(5)
     ele1.click()
     # 任意选择一张图片
     xpath1 = '//a[@ng-click="imageChoose($index, list)"]'
     time.sleep(1)
     # els = WebDriverWait(driver, TIME_OUT).until(EC.presence_of_all_elements_located((By.XPATH, xpath1)))
     els = driver.find_elements_by_xpath(xpath=xpath1)
     if index == None:
         index = random.randrange(0, len(els))
     # import pdb;pdb.set_trace()
     time.sleep(1)
     els[index].click()
     time.sleep(1)
     # 点击确定按钮
     xpath2 = '//*[@id="submitImage"]'
     sure = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath(xpath=xpath2))
     time.sleep(1)
     sure.click()
     time.sleep(1)
Exemplo n.º 29
0
 def getComments(self):
     """
     Get the comments of the current picture.
         
     Returns:
         A list of comments of the picture, where a <comment> is a shortlist
         with the comment itself and the user of the comment.
     """
     while True:
         try:
             more = WebDriverWait(self.driver, 1).until(EC.presence_of_element_located((By.ID, INFOS['viewMore'])))
             more.click()
         except:
             break
     
     soup = BeautifulSoup(self.driver.page_source, 'html.parser')
     myComments = []
     allComments = soup.find('ol', {'id': INFOS['picComments']}).find_all('li')
     for comment in allComments:
         try:
             start = comment.find('div', {'class': 'h-mavatar'})
             user = start.find('div').find('h3').find('a').getText()
             comm = start.find('p', {'class': INFOS['comment']}).getText()
             myComments.append([comm, user])
         except:
             pass
         
     return myComments
Exemplo n.º 30
0
	def test_dodajPozF(self):
		driver = self.driver
		driver.switch_to_window(driver.window_handles[1])
		print "-------------okno: "+driver.title +"------------"
		print driver.current_url	
		
		add_rowBtn = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id("add_row"))
		add_rowBtn.click()   
		print "add row"
	
		elements_nameField = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_name("elements[name][]"))
		elements_nameField.send_keys(elements_name) 
		print "nazwa" + elements_name
		amountField = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_name("elements[amount][]"))
		amountField.send_keys(amount) 
		print "ilosc" + amount
		unit_priceField = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_name("elements[unit_price][]"))
		unit_priceField.send_keys(unit_price) 
		print "cena jedn"+ unit_price
		
		def save_elements():
			save_elementsBtn = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id("save_elements"))
			save_elementsBtn.click()
		def reload():
			
				save_elements()
		reload()
Exemplo n.º 31
0
def bypassSignIn(driver):
    nothanks = WebDriverWait(driver, 30).until(EC.element_to_be_clickable(
        (By.CLASS_NAME, "style-scope.yt-button-renderer.style-text.size-small")))
    nothanks.click()
    time.sleep(random.randint(1, 5))
    bypassAgree(driver)