python类ID的实例源码

test_ng.py 文件源码 项目:pyselenium-js 作者: neetjn 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_ng_debugging(self):
        """Test: Enable angular debugging and verify binded elements"""
        self.page.js.ng_enable_debugging()
        WebDriverWait(self.page.browser, 5).until(EC.presence_of_element_located((By.ID, 'app')))
        self.page.js.trigger_event(
            element=self.page.user_name_field,
            event='focus'
        )  # wait for page reload
        self.assertGreater(
            len(self.page.binded_elements), 0,
            'Expected at least one binded element found none'
        )
bot.py 文件源码 项目:sbu-bot 作者: danielamorais 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def login(email, senha, firefox):
    firefox.get('http://acervus.unicamp.br/asp/login.asp?modo_busca=rapida&content=mensagens&iBanner=0&iEscondeMenu=0&iSomenteLegislacao=0&iIdioma=0')
    firefox.implicitly_wait(10)
    WebDriverWait(firefox, 60).until(EC.visibility_of_element_located((By.ID, 'button1')))
    try:
        input_login = firefox.find_element_by_name("codigo")
        input_login.send_keys(email)
        input_pwd = firefox.find_element_by_name("senha")
        input_pwd.send_keys(senha)
        send_button = firefox.find_element_by_id("button1")
        send_button.click()
        WebDriverWait(firefox, 30).until(EC.visibility_of_element_located((By.CLASS_NAME, 'justificado')))
    except Exception, err:
        error_message = "Erro no login. Verifique usuário e senha."
        print error_message
        logging.exception(error_message)
        raise
    return
ticketing_layer.py 文件源码 项目:Tktr 作者: Intuity 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def create_ticket_type(cls, name=None, description=None, cost=None, release=True, quantity=100):
        # Fill dummy data if not provided
        if name == None: name = str(randint(0, 100000))
        if description == None: description = "This is the demo description for %s" % name
        if cost == None: cost = str(randint(0, 200))
        else: cost = "%.2f" % (cost / 100.0)
        # Enact an administration login
        cls.admin_login()
        # Go to the ticket type add page
        cls.browser.get(cls.route_path("admin_ticket_type_add"))
        cls.browser.find_element(By.ID, "name").send_keys(name)
        cls.browser.find_element(By.ID, "description").send_keys(description)
        cls.browser.find_element(By.ID, "cost").send_keys(cost)
        # Check the group boxes so that purchaase is allowed
        cls.browser.find_element(By.ID, "raven-group").click()
        cls.browser.find_element(By.ID, "admin-group").click()
        cls.browser.find_element(By.ID, "alumni-group").click()
        cls.browser.find_element(By.ID, "committee-group").click()
        cls.browser.find_element(By.ID, "submit").click()
        # Ensure it added
        cls.browser.get(cls.route_path("admin_tickets"))
        assert name in cls.browser.page_source
        # If we have been told to release then do so
        if release: cls.release_tickets(name, quantity=quantity)
        # Logout of admin account
        cls.logout()
        # Return its details
        return (name, description, cost, quantity)
ticketing_layer.py 文件源码 项目:Tktr 作者: Intuity 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def release_tickets(cls, type_name, quantity=100):
        # Login
        cls.admin_login()
        # Find the release link and click it
        cls.browser.get(cls.route_path("admin_tickets"))
        row = 1
        found = False
        while cls.is_element_present("//table/tbody/tr[%i]/td[1]" % row):
            name = cls.browser.find_element_by_xpath("//table/tbody/tr[%i]/td[1]" % row).text
            if type_name in name:
                cell = cls.browser.find_element_by_xpath("//table/tbody/tr[%i]/td[4]" % row)
                cell.find_element(By.CLASS_NAME, "release_tick_link").click()
                found = True
                break
            row += 1
        assert found, "Didn't find release link for ticket type!"
        # Now actually release some tickets
        cls.browser.find_element(By.ID, "number").send_keys(str(quantity))
        cls.browser.find_element(By.ID, "submit").click()
        # Deal with modal alert
        try:
            cls.browser.switch_to_alert().accept()
        except Exception:
            pass # Catch for PhantomJS
        # Logout
        cls.logout()
        # Return quantity
        return quantity
raven.py 文件源码 项目:Tktr 作者: Intuity 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def raven_login(cls, crsid=None, password=None, fill_details=True):
        if crsid == None:
            crsid = "test0%03d" % ( randint(0, 400) )
            password = "test"
        # First ensure we are logged out
        cls.logout()
        # Now login
        cls.browser.get("http://localhost:%i/" % cls.port_num)
        # Click the raven link
        link = cls.browser.find_element(By.ID, "ravenbutton")
        link.click()
        sleep(1)
        # We should now be at the Raven testing login page
        assert "Demonstration Authentication Service" in cls.browser.page_source
        assert Raven.our_description in cls.browser.page_source
        # Fill in the login details
        user = cls.browser.find_element(By.ID, "userid")
        user.send_keys(crsid)
        pwd = cls.browser.find_element(By.ID, "pwd")
        pwd.send_keys(password)
        cls.browser.find_element(By.NAME, "credentials").submit()
        # Fill details automatically fills the profile
        if fill_details:
            filled_state = {
                "fullname": "Automated Test User",
                "dob_day": "15",
                "dob_month": "3",
                "dob_year": "1987",
                "photofile": cls.root_path() + "/data/profile_images/dummy.png",
                "college": "sidney-sussex",
                "grad_status": "undergrad",
            }
            # Now run a full valid fill and check for no validation fault
            cls.browser.get(cls.route_path("user_profile_edit"))
            for key in filled_state:
                cls.browser.find_element(By.ID, key).send_keys(filled_state[key])
            # Submit
            cls.browser.find_element(By.ID, "submit").click()
        # Return credentials used
        return (crsid, password)
base.py 文件源码 项目:Tktr 作者: Intuity 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def admin_login(cls, username=None, password=None):
        # Fill the default values
        if username == None:
            username = "admin"
            password = "password"
        # Logout, then login
        cls.logout()
        cls.browser.get(cls.route_path("admin_login"))
        cls.browser.get(cls.route_path("admin_login"))
        time.sleep(1) # Just ensure we are here
        cls.browser.find_element(By.ID, "username").send_keys(username)
        cls.browser.find_element(By.ID, "password").send_keys(password)
        cls.browser.find_element(By.ID, "submit").click()
        # Return login credentials used
        return (username, password)
common.py 文件源码 项目:picoCTF 作者: royragsdale 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def find_id_with_timeout(driver, ID, timeout=TIMEOUT):
    return WebDriverWait(driver, timeout).until(
        EC.presence_of_element_located((By.ID, ID))
    )
common.py 文件源码 项目:picoCTF 作者: royragsdale 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def find_visible_id_with_timeout(driver, ID, timeout=TIMEOUT):
    return WebDriverWait(driver, timeout).until(
            EC.visibility_of_element_located((By.ID, ID))
    )
BrowserTest.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _change_focus(self, by, selector, focus = True, message = None):
        description = self.describeElement(by, selector)
        wait_for = self.getDefaultWaitFor()
        change = 'focus' if focus else 'blur'
        element = self.assertElementPresent(by, selector, message, wait_for = wait_for)
        self.log("{0} on {1}{2}".format(change, description, \
            ", because " + message if message else ""))
        script = ""
        if by == By.ID:
            script = "jQuery(\"#{0}\")".format(selector)
        elif by == By.CSS_SELECTOR:
            script = "jQuery(\"{0}\")".format(selector)
        else:
            self.onFail(by, selector, message, "Cannot {0} for this selector type (yet).".\
                format(change))
        script = "{0}.{1}();".format(script, change)
        self.log("{0} on {1} using {2}".format(change, description, script))
        self.driver.execute_script(script)
        return element
BrowserTest.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def populateFormByID(self, formData):
        for form_id, value in formData.iteritems():
            self.sendKeys(By.ID, form_id, value, message = "Setting form field")
webelement.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def find_element_by_id(self, id_):
        """Finds element within this element's children by ID.

        :Args:
            - id_ - ID of child element to locate.
        """
        return self.find_element(by=By.ID, value=id_)
webelement.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def find_elements_by_id(self, id_):
        """Finds a list of elements within this element's children by ID.

        :Args:
            - id_ - Id of child element to find.
        """
        return self.find_elements(by=By.ID, value=id_)
webelement.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def id(self):
        """Internal ID used by selenium.

        This is mainly for internal use. Simple use cases such as checking if 2
        webelements refer to the same element, can be done using ``==``::

            if element1 == element2:
                print("These 2 are equal")

        """
        return self._id
webelement.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def find_elements(self, by=By.ID, value=None):
        if not By.is_valid(by) or not isinstance(value, str):
            raise InvalidSelectorException("Invalid locator values passed in")

        if self._w3c:
            if by == By.ID:
                by = By.CSS_SELECTOR
                value = '[id="%s"]' % value
            elif by == By.TAG_NAME:
                by = By.CSS_SELECTOR
            elif by == By.CLASS_NAME:
                by = By.CSS_SELECTOR
                value = ".%s" % value
            elif by == By.NAME:
                by = By.CSS_SELECTOR
                value = '[name="%s"]' % value

        return self._execute(Command.FIND_CHILD_ELEMENTS,
                             {"using": by, "value": value})['value']
webdriver.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def find_element_by_id(self, id_):
        """Finds an element by id.

        :Args:
         - id\_ - The id of the element to be found.

        :Usage:
            driver.find_element_by_id('foo')
        """
        return self.find_element(by=By.ID, value=id_)
webdriver.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def find_elements_by_id(self, id_):
        """
        Finds multiple elements by id.

        :Args:
         - id\_ - The id of the elements to be found.

        :Usage:
            driver.find_elements_by_id('foo')
        """
        return self.find_elements(by=By.ID, value=id_)
webdriver.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def find_element(self, by=By.ID, value=None):
        """
        'Private' method used by the find_element_by_* methods.

        :Usage:
            Use the corresponding find_element_by_* instead of this.

        :rtype: WebElement
        """
        if not By.is_valid(by) or not isinstance(value, str):
            raise InvalidSelectorException("Invalid locator values passed in")
        if self.w3c:
            if by == By.ID:
                by = By.CSS_SELECTOR
                value = '[id="%s"]' % value
            elif by == By.TAG_NAME:
                by = By.CSS_SELECTOR
            elif by == By.CLASS_NAME:
                by = By.CSS_SELECTOR
                value = ".%s" % value
            elif by == By.NAME:
                by = By.CSS_SELECTOR
                value = '[name="%s"]' % value
        return self.execute(Command.FIND_ELEMENT,
                             {'using': by, 'value': value})['value']
webdriver.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def find_elements(self, by=By.ID, value=None):
        """
        'Private' method used by the find_elements_by_* methods.

        :Usage:
            Use the corresponding find_elements_by_* instead of this.

        :rtype: list of WebElement
        """
        if not By.is_valid(by) or not isinstance(value, str):
            raise InvalidSelectorException("Invalid locator values passed in")
        if self.w3c:
            if by == By.ID:
                by = By.CSS_SELECTOR
                value = '[id="%s"]' % value
            elif by == By.TAG_NAME:
                by = By.CSS_SELECTOR
            elif by == By.CLASS_NAME:
                by = By.CSS_SELECTOR
                value = ".%s" % value
            elif by == By.NAME:
                by = By.CSS_SELECTOR
                value = '[name="%s"]' % value

        return self.execute(Command.FIND_ELEMENTS,
                             {'using': by, 'value': value})['value']
event_firing_webdriver.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def find_elements(self, by=By.ID, value=None):
        return self._dispatch("find", (by, value, self._driver), "find_elements", (by, value))


问题


面经


文章

微信
公众号

扫码关注公众号