当前位置: 首页>>代码示例>>Python>>正文


Python Browser.is_element_not_present_by_value方法代码示例

本文整理汇总了Python中splinter.Browser.is_element_not_present_by_value方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_not_present_by_value方法的具体用法?Python Browser.is_element_not_present_by_value怎么用?Python Browser.is_element_not_present_by_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在splinter.Browser的用法示例。


在下文中一共展示了Browser.is_element_not_present_by_value方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DownPatent

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_value [as 别名]
class DownPatent(object):
    def __init__(self, db, down_url):
        self.db = db
        self.down_url = down_url
        self.browser = Browser("phantomjs", wait_time=10)
        #self.browser = Browser()

    #下载专利
    def download(self, patentno):
        #访问网页
        #网页加载超时
        #down_flag, 0:未下载,1:不存在,2:下载失败
        download_link = ""
        down_flag = 0
        if True:
            print "打开网页"
            self.browser.visit(self.down_url)
            if not self.browser.is_element_not_present_by_value("查询", wait_time=10):
                #填写专利号
                self.browser.fill("cnpatentno", patentno)
                self.browser.find_by_value("查询").first.click()
                print "填写专利号"
                #连接超时,404
                if self.browser:
                    print "打开验证码网页"
                    #一个最多循环20次
                    code_handler = CodeHandler()
                    #填写验证码
                    list_fill_text = []
                    #验证码路径
                    list_code_path = []
                    #验证码分割标志
                    list_split_flag = []
                    #验证码识别标志
                    list_reg_flag = []
                    for code_num in xrange(20):
                        print code_num
                        #查找验证码
                        if not self.browser.is_element_not_present_by_id("getcode", wait_time=5):
                            print "查找验证码"
                            #截图
                            #self.browser.driver.maximize_window()
                            self.browser.driver.save_screenshot("screenshot.png")
                            #获取验证码图片
                            image = Image.open("screenshot.png")
                            image_location = self.find_location(image)
                            image_code = image.crop((image_location[0], image_location[1], image_location[0]+52, image_location[1]+21))
                            save_path = "static/images/onlinecode/" + time.ctime() + ".png"
                            save_path_temp = "../%s" % save_path
                            image_code.save(save_path_temp)
                            list_code_path.append(save_path)

                            #分割图片
                            list_split_image = self.deal_split(code_handler, image_code)
                            
                            #识别,如果能正确识别,则识别,不能,则重新获取验证码      
                            if len(list_split_image) == 4:
                                print "正确分割"
                                list_split_flag.append(1)
                                reg_plain_text = self.reg_code(list_split_image)
                                fill_text = "".join(reg_plain_text)
                                list_fill_text.append(fill_text)
                                #填写验证码
                                #hand_fill_text = raw_input("Enter fill text:")
                                self.browser.fill("ValidCode", fill_text)
                                self.browser.find_by_value("确定").first.click()

                                print self.browser.html.encode("utf-8").find("验证码输入错误") 
                                if self.browser.html.encode("utf-8").find("验证码输入错误") == -1:
                                    list_reg_flag.append(1)
                                    if self.browser.html.encode("utf-8").find("没有找到该专利") == -1:
                                        down_link_one = self.browser.find_link_by_text("申请公开说明书图形下载(标准版)")
                                        down_link_two = self.browser.find_link_by_text("申请公开说明书图形下载(极速版)")
                                        if down_link_one or down_link_two:
                                            print "查找说明书图形下载链接"
                                            list_reg_flag.append(1)
                                            if down_link_one:
                                                self.browser.click_link_by_text("申请公开说明书图形下载(标准版)")
                                            else:
                                                self.browser.click_link_by_text("申请公开说明书图形下载(极速版)")
                                            
                                            print "查找下载链接"
                                            #查找下载链接
                                            download_a = self.browser.find_link_by_text("下载专利")
                                            if download_a:
                                                download_link = download_a["href"]
                                            
                                                #找到下载链接
                                                down_flag = 3
                                                break
                                            else:
                                                print "下载失败"
                                                #下载失败
                                                down_flag = 2
                                                break
                                        '''
                                        else:
                                            print "识别正确,未找到链接"
                                            list_reg_flag.append(0)
                                            self.browser.back()
#.........这里部分代码省略.........
开发者ID:happyin3,项目名称:captchaimgs,代码行数:103,代码来源:patentclass.py

示例2: TagTest

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_value [as 别名]
class TagTest(StaticLiveServerTestCase):
    def setUp(self):
        fss.remove_tree(settings.MEDIA_ROOT)
        check_permissions()
        set_site(self.live_server_url)
        
        self.browser = Browser()
        self.browser.visit(self.live_server_url)
        
        login_url = settings.LOGIN_URL
        self.browser.click_link_by_partial_href(login_url)
        
        username = 'antonio'
        password = 'antonio'
        create_user(username)
        login(
            self.browser,
            username,
            password,
        )
        
        upload_url = reverse('documents.views.add_document')
        self.browser.click_link_by_partial_href(upload_url)
        
        source = 'local'
        docfile = get_abs_path('doctest.pdf')
        language = 'eng'
        public = True
        title = 'test'
        notes = 'test notes'
        upload(
            self.browser,
            source,
            docfile,
            language,
            public,
            title,
            notes,
        )
        
        self.browser.is_element_not_present_by_value('ready', 10)
        
        tag = 'tag'
        add_tag(
            self.browser,
            tag,
        )
        
        self.tag = tag
        self.tag_obj = get_tag(tag)
    
    def test_add_tag(self):
        tag_exists = exists_tag(self.tag)
        self.assertTrue(tag_exists)
        self.assertEquals(self.tag_obj.name, self.tag)
        
        document_list_url = \
            self.live_server_url + reverse('documents.views.list_documents')
        self.assertEquals(self.browser.url, document_list_url)
        
        tag_span = self.browser.find_by_css('span.taggit_tag')
        self.assertEquals(tag_span.value, self.tag)
        
#        import time; time.sleep(3)
        self.browser.quit()
    
    def test_add_different_tag(self):
        old_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        
        tag = 'other'
        add_tag(
            self.browser,
            tag,
        )
        
        new_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        self.assertEquals(new_tag_num, old_tag_num + 1)
        
#        import time; time.sleep(3)
        self.browser.quit()
    
    def test_add_same_tag(self):
        old_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        
        tag = self.tag
        add_tag(
            self.browser,
            tag,
        )
        
        new_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        self.assertEquals(new_tag_num, old_tag_num)
        
#        import time; time.sleep(3)
        self.browser.quit()
    
    def test_remove_tag(self):
        old_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        
        driver = self.browser.driver
#.........这里部分代码省略.........
开发者ID:CulturePlex,项目名称:festos,代码行数:103,代码来源:test_tag.py

示例3: SearchTest

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_value [as 别名]
class SearchTest(StaticLiveServerTestCase):
    def setUp(self):
        fss.remove_tree(settings.MEDIA_ROOT)
        check_permissions()
        set_site(self.live_server_url)
        
        self.browser = Browser()
        self.browser.visit(self.live_server_url)
        
        login_url = settings.LOGIN_URL
        self.browser.click_link_by_partial_href(login_url)
        
        username = 'antonio'
        password = 'antonio'
        create_user(username)
        login(
            self.browser,
            username,
            password,
        )
        
        upload_url = reverse('documents.views.add_document')
        self.browser.click_link_by_partial_href(upload_url)
        
        source = 'local'
        docfile = get_abs_path('doctest.pdf')
        language = 'eng'
        public = True
        title = 'test'
        notes = 'test notes'
        upload(
            self.browser,
            source,
            docfile,
            language,
            public,
            title,
            notes,
        )
        
        self.browser.is_element_not_present_by_value('ready', 10)
        
        self.title = title
        import time; time.sleep(1)
    
    def test_search_title(self):
        self.browser.visit(self.live_server_url)
        
        title = 'test'
        
        driver = self.browser.driver
        actions = ActionChains(driver)
        searchbar_xpath = '//*[@id="search"]/div/div/div[2]'
        searchbar_div = driver.find_element_by_xpath(searchbar_xpath)
        actions.move_to_element(searchbar_div)
        actions.click()
        actions.perform()
        
        menu_title_xpath = '/html/body/ul/li[4]/a'
        menu_title = self.browser.find_by_xpath(menu_title_xpath)
        menu_title.click()
        input_title_xpath = \
            '//*[@id="search"]/div/div/div[2]/div[2]/div[2]/input'
        input_title = self.browser.find_by_xpath(input_title_xpath)
        input_title.type(title + '\r')
        
        search_list_url = \
            self.live_server_url + '/?title=' + title + '&'
        self.assertEquals(self.browser.url, search_list_url)
        
        summary_xpath = '/html/body/div/div[2]/p/small'
        summary = self.browser.find_by_xpath(summary_xpath)
        self.assertEquals(summary.value, '1 documents found')
        
        document_img_xpath = '/html/body/div/div[2]/ul/li/a/img'
        document_img = self.browser.find_by_xpath(document_img_xpath).click()
        viewer_title_xpath = (
            '//*[@id="documentviewer-container"]'
            '/div/div[1]/div[1]/div[1]/div[2]/h4/a'
        )
        viewer_title = self.browser.find_by_xpath(viewer_title_xpath)
        self.assertEquals(viewer_title.value, self.title)
        
#        import time; time.sleep(3)
        self.browser.quit()
    
    def test_search_text(self):
        self.browser.visit(self.live_server_url)
        
        text = 'download'
        
        driver = self.browser.driver
        actions = ActionChains(driver)
        searchbar_xpath = '//*[@id="search"]/div/div/div[2]'
        searchbar_div = driver.find_element_by_xpath(searchbar_xpath)
        actions.move_to_element(searchbar_div)
        actions.click()
        actions.perform()
        
        menu_text_xpath = '/html/body/ul/li[3]/a'
#.........这里部分代码省略.........
开发者ID:CulturePlex,项目名称:festos,代码行数:103,代码来源:test_search.py

示例4: DocTest

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_value [as 别名]
class DocTest(StaticLiveServerTestCase):
    def setUp(self):
        fss.remove_tree(settings.MEDIA_ROOT)
        check_permissions()
        set_site(self.live_server_url)
        
        self.browser = Browser()
        self.browser.visit(self.live_server_url)
        
        login_url = settings.LOGIN_URL
        self.browser.click_link_by_partial_href(login_url)
        
        username = 'antonio'
        password = 'antonio'
        create_user(username)
        login(
            self.browser,
            username,
            password,
        )
        
        upload_url = reverse('documents.views.add_document')
        self.browser.click_link_by_partial_href(upload_url)
        
        source = 'local'
        docfile = get_abs_path('doctest.pdf')
        language = 'eng'
        public = True
        title = 'test'
        notes = 'test notes'
        upload(
            self.browser,
            source,
            docfile,
            language,
            public,
            title,
            notes,
        )
        
        self.browser.is_element_not_present_by_value('ready', 10)
        
        self.public = public
        self.title = title
        self.notes = notes
        self.document = get_document(title)
    
    def test_upload_doc_local(self): #Create
        document_exists = exists_document(self.title)
        self.assertTrue(document_exists)
        self.assertEquals(self.document.public, self.public)
        self.assertEquals(self.document.title, self.title)
        self.assertEquals(self.document.notes, self.notes)
        
        document_list_url = \
            self.live_server_url + reverse('documents.views.list_documents')
        self.assertEquals(self.browser.url, document_list_url)
        
        document_xpath = '/html/body/div/div[2]/table/tbody/tr[1]'
        document_tr = self.browser.find_by_xpath(document_xpath)
        document_id = document_tr['data-id']
        self.assertEquals(int(document_id), self.document.id)
        
        document_title_xpath = '//*[@id="documents_cell"]/span[1]'
        document_title = self.browser.find_by_xpath(document_title_xpath)
        self.assertEquals(document_title.value, self.title)
        
        profile_xpath = '/html/body/div/div[1]/div/ul[2]/li[4]/a'
        profile_link = self.browser.find_by_xpath(profile_xpath)
        owner_xpath = '/html/body/div/div[2]/table/tbody/tr[1]/td[4]/a'
        owner_link = self.browser.find_by_xpath(owner_xpath)
        self.assertEquals(profile_link.value, owner_link.value)
        
        status_xpath = '/html/body/div/div[2]/table/tbody/tr/td[5]/div'
        status_div = self.browser.find_by_xpath(status_xpath)
        self.assertEquals(status_div.value, self.document.status)
        
        numpages_xpath = '/html/body/div/div[2]/table/tbody/tr[1]/td[6]/div'
        numpages_div = self.browser.find_by_xpath(numpages_xpath)
        self.assertEquals(int(numpages_div.value), self.document.page_count)
        
        privacy_icon_xpath = '//*[@id="privacy"]/i'
        privacy_icon = self.browser.find_by_xpath(privacy_icon_xpath)
        self.assertTrue(privacy_icon.has_class('icon-eye-open'))
        
        structure = create_structure(self.document)
        root_path = self.document.get_root_path()
        dirs = fss.listdir(root_path)[0]
        files = fss.listdir(root_path)[1]
        for d in dirs:
            dir_path = os.path.join(root_path, d)
            for f in structure['dirs'][d]:
                self.assertIn(f, fss.listdir(dir_path)[1])
        for f in structure['files']:
            self.assertIn(f, fss.listdir(root_path)[1])
        
#        import time; time.sleep(3)
        self.browser.quit()
#    
#    def test_upload_doc_dropbox(self): #Create
#.........这里部分代码省略.........
开发者ID:CulturePlex,项目名称:festos,代码行数:103,代码来源:test_document.py


注:本文中的splinter.Browser.is_element_not_present_by_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。