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


Python WebDriverWait.find_elements_by_xpath方法代码示例

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


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

示例1: parse_page

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
    def parse_page(self, link, browser):

        browser.implicitly_wait(TplinkSpider.timeout)
        browser.set_page_load_timeout(TplinkSpider.timeout)
        try:
            browser.get(link)
        except TimeoutException:
            pass

        element = WebDriverWait(browser, TplinkSpider.timeout).until(
            EC.presence_of_element_located((By.CLASS_NAME, "download")))
        lines = element.find_elements_by_xpath(
            "table/tbody/tr[position()<last()]")
        item = BasicItem()
        item["Firm"] = "Tplink"
        item["Info"] = {}
        for l in lines:
            key = l.find_element_by_xpath("td[1]").text.lstrip()
            val = l.find_element_by_xpath("td[2]")
            if key == u"立即下载":
                item["Link"] = val.find_element_by_xpath(
                    "a").get_attribute("href")
                item["Rawlink"] = item["Link"]
                item["Filename"] = item["Rawlink"].rsplit("/", 1).pop()
            elif key == u"软件名称":
                item["Title"] = val.text
            elif key == u"软件简介":
                item["Descr"] = val.text
            else:
                item["Info"][key] = val.text
        return item
开发者ID:kooksee,项目名称:firmSpyder,代码行数:33,代码来源:tplinkSpider.py

示例2: getEditorSelectionButton

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
 def getEditorSelectionButton(self, expectedButtonId):
    editorButtonsContainer = WebDriverWait(self.__newRuleModalWebElement, 10).until(Condition.visibility_of_element_located((By.CLASS_NAME, "editor-btns")))
    editorButtons = editorButtonsContainer.find_elements_by_xpath("./child::*")
    codeButtonFound = False
    for editorButton in editorButtons:
       if (editorButton.find_element_by_tag_name("span").get_attribute("id") == expectedButtonId):
          return editorButton
    assert False
开发者ID:Yadoms,项目名称:yadoms,代码行数:10,代码来源:__init__.py

示例3: _getLevels

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
 def _getLevels(self, driver, tableId ):
     tableDiv  = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, tableId )))
     levelElements = tableDiv.find_elements_by_xpath( ".//div/div/div/div/div/div[@class='qooxdoo-table-cell']")
     levelCount = len(levelElements)
     levelList = []
     for i in range(levelCount):
         print 'Text=', levelElements[i].text
         levelList.append( levelElements[i].text)
     return levelList
开发者ID:Astroua,项目名称:CARTAvis,代码行数:11,代码来源:tContour.py

示例4: get_project_metadata

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
    def get_project_metadata(self, project_name):
        self.search_input = project_name
        element = WebDriverWait(self.browser, TMO).until(
                      lambda browser: browser.find_element_by_link_text(project_name))

        elements = element.find_elements_by_xpath('../../td')

        metadata = {
            "name":        elements[0].text,
            "description": elements[1].text,
            "version":     elements[2].text,
            "created":     elements[3].text,
            "last_saved":  elements[4].text,
        }

        return metadata
开发者ID:Daiyu506,项目名称:OpenMDAO-Framework,代码行数:18,代码来源:project.py

示例5: test_menu_hideClipping

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
    def test_menu_hideClipping(self):    
        driver = self.driver

        # Click on an CasaImageLoader Window so that clipping is available on the menu.
        imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
        ActionChains(driver).click(imageWindow).perform()

        # Verify that clipping commands can be found on the menu bar.
        menuBar = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Menu.MenuBar']")))
        self.assertIsNotNone( menuBar, "Could not find the menu bar")
        clipping = menuBar.find_elements_by_xpath( "./div[contains(text(), 'Clipping')]" )
        self.assertIsNotNone( clipping, "Clipping not present on menu bar");

        # Now right click the toolbar
        toolBar = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Menu.ToolBar']")))
        self.assertIsNotNone( toolBar, "Could not find the tool bar")
        actionChains = ActionChains(driver)
        actionChains.context_click(toolBar).perform()

        # Find and click the customize button
        customizeButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Customize...']/..")))
        self.assertIsNotNone( customizeButton, "Could not find the customize button in context")
        ActionChains(driver).click( customizeButton).perform()
        
        # Uncheck clipping
        clippingButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Clipping']/preceding-sibling::div/div")))
        self.assertIsNotNone( clippingButton, "Could not clipping button in customize dialog")
        styleAtt = clippingButton.get_attribute( "style");
        print "Style", styleAtt
        if "checked.png" in styleAtt:
            print "Clipping checked"
            clipParent = clippingButton.find_element_by_xpath( '..')
            ActionChains(driver).click( clipParent ).perform()
        
        # Check that the clipping menu item is no longer available
        try: 
            clipButton = menuBar.find_element_by_xpath( "./div[contains(text(), 'Clipping')]" )
            self.assertTrue( False, "Should not be able to locate clipping button")
        except Exception:
            print "Test succeeded because we should not be able to find clipping"   
开发者ID:pfederl,项目名称:CARTAvis,代码行数:42,代码来源:tMenuToolVisibility.py

示例6: crawl_channel_inner

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
def crawl_channel_inner(site):
    webdriver_client = get_webdriver_client()
    try:
        try:
            webdriver_client.get(site.crawl_url)
        except (NoSuchElementException, TimeoutException):
            current_app.logger.error('调用接口失败: 内容获取失败')
            return False
        current_app.logger.info('扫描主目录:{}'.format(site.crawl_url))
        try:
            dirul = WebDriverWait(webdriver_client, 30).until(lambda x: x.find_element_by_xpath('//ul[contains(@class,\'video-list\')]'))
        except TimeoutException:
            current_app.logger.error('调用接口失败: 等待读取频道内容失败')
            return False
        site.channels.update({'valid': False})
        for channel_a_element in dirul.find_elements_by_xpath('./li/a'):
            img_element = channel_a_element.find_element_by_xpath('./div[@class=\'img-container\']/img')
            div_element = channel_a_element.find_element_by_xpath('./div[@class=\'cate-title\']')
            channel_name = div_element.get_attribute('innerHTML')
            channel_url = channel_a_element.get_attribute('href')
            channel = LiveTVChannel.query.filter_by(url=channel_url).one_or_none()
            if not channel:
                channel = LiveTVChannel(url=channel_url)
                current_app.logger.info('新增频道 {}:{}'.format(channel_name, channel_url))
            else:
                current_app.logger.info('更新频道 {}:{}'.format(channel_name, channel_url))
            channel.site = site
            channel.name = channel_name
            channel.short_name = channel_url[channel_url.rfind('/')+1:]
            channel.image_url = img_element.get_attribute('src')
            channel.icon_url = img_element.get_attribute('src')
            channel.valid = True
            db.session.add(channel)
        site.last_crawl_date = datetime.utcnow()
        db.session.add(site)
        db.session.commit()
        return True
    finally:
        webdriver_client.close()
        webdriver_client.quit()
开发者ID:liaun,项目名称:livetv_mining,代码行数:42,代码来源:panda.py

示例7: crawl_channel_inner

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
def crawl_channel_inner(site):
    webdriver_client = get_webdriver_client()
    try:
        try:
            webdriver_client.get(site.crawl_url)
        except TimeoutException:
            current_app.logger.error('调用接口失败: 内容获取失败')
            return False
        current_app.logger.info('扫描主目录:{}'.format(site.crawl_url))
        try:
            dirul = WebDriverWait(webdriver_client, 30).until(lambda x: x.find_element_by_xpath('//ul[@id=\'game-list-panel\']'))
        except TimeoutException:
            current_app.logger.error('调用接口失败: 等待读取频道内容失败')
            return False
        site.channels.update({'valid': False})
        for channel_a_element in dirul.find_elements_by_xpath('./li/div/a'):
            p_element = channel_a_element.find_element_by_xpath('./p')
            img_element = channel_a_element.find_element_by_xpath('./img')
            channel_name = p_element.get_attribute('innerHTML')
            channel_url = channel_a_element.get_attribute('href')
            channel = LiveTVChannel.query.filter_by(url=channel_url).one_or_none()
            if not channel:
                channel = LiveTVChannel(url=channel_url)
                current_app.logger.info('新增频道 {}:{}'.format(channel_name, channel_url))
            else:
                current_app.logger.info('更新频道 {}:{}'.format(channel_name, channel_url))
            channel.site = site
            channel.name = channel_name
            channel.image_url = img_element.get_attribute('src')
            channel.icon_url = img_element.get_attribute('src')
            channel.valid = True
            db.session.add(channel)
        site.last_crawl_date = datetime.utcnow()
        db.session.add(site)
        db.session.commit()
        return True
    finally:
        webdriver_client.close()
        webdriver_client.quit()
开发者ID:liaun,项目名称:livetv_mining,代码行数:41,代码来源:zhanqi.py

示例8: __runJSTests

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
    def __runJSTests(self, haha=None, kkkk=None):
        for i_case in self.tests_json['cases']:
            with EXE_LOCK:
                if self.exe_status == 'DONE':
                    return False
            i_case['start_at'] = time.strftime(
                "%Y-%m-%d %H:%M:%S", time.localtime())
            try:
                sub_index = 0
                url_equal = False
                tmp_pos = i_case['entry'].find('?')
                if tmp_pos == -1:
                    entry_url = i_case['entry']
                else:
                    entry_url = i_case['entry'][:tmp_pos]

                if not self.pre_url:
                    self.pre_url = entry_url
                else:
                    url_equal = self.__checkUrlSame(self.pre_url, i_case['entry'])
                    self.pre_url = entry_url
                i_case_timeout = i_case['timeout']
            except Exception, e:
                i_case_timeout = DEFAULT_TIMEOUT

            i_page_url = '%s%s' % (self.test_prefix, entry_url)
            try:
                sub_index = self.__getCaseIndex(i_case['entry'])
                if not url_equal:
                    self.web_driver.get(i_page_url)
                    table_elem = WebDriverWait(self.web_driver, int(i_case['onload_delay'])).until(EC.presence_of_element_located((By.XPATH, "//table[@id='results']")))
                    self.pre_tr_list = table_elem.find_elements_by_xpath(".//tbody/tr")

                if sub_index:
                    sub_index = int(sub_index) - 1
                    tr = self.pre_tr_list[sub_index]
                    sub_result = tr.find_elements_by_xpath(".//td")[0].text
                    if sub_result.upper() == 'PASS':
                        i_case['result'] = STR_PASS
                    elif sub_result.upper() == 'FAIL':
                        i_case['result'] = STR_FAIL
                        error_message = tr.find_elements_by_xpath(".//td")[2].text
                        i_case['stdout'] = error_message
                    else:
                        i_case['result'] = STR_BLOCK
                else:
                    pass_result = self.web_driver.find_elements_by_class_name('pass')
                    fail_result = self.web_driver.find_elements_by_class_name('fail')
                    if len(fail_result) > 0:
                        i_case['result'] = STR_FAIL
                    elif len(pass_result) > 0 and len(fail_result) == 0:
                        i_case['result'] = STR_PASS
                    else:
                        i_case['result'] = STR_BLOCK
                    result_message = ["[Message]"]
                    for tr in self.pre_tr_list:
                        td = tr.find_elements_by_xpath(".//td")
                        result_message.append("[assert]%s[id]%s[message]*%s" % (td[0].text, td[1].text, td[2].text))
                    i_case['stdout'] = "".join(result_message)
                    del result_message
                i_case['end_at'] = time.strftime(
                    "%Y-%m-%d %H:%M:%S", time.localtime())
            except Exception, e:
                try:
                    console_elem = self.web_driver.find_element_by_id("console")
                    if console_elem is not None:
                        result_list = []
                        result_str = '[Message]'
                        span_list = console_elem.find_elements_by_xpath(".//span/span")
                        parsed_flag = False
                        if span_list:
                            for span_elem in span_list:
                                if not span_elem.get_attribute('class'):
                                    result_info = span_elem.text.split(' ', 1)
                                    if result_info[1].find("successfullyParsed") == -1:
                                        case_result = result_info[0]
                                        result_list.append(case_result)
                                        tmp_msg = "[message]*okay"
                                        if case_result == "FAIL":
                                            tmp_msg = "[message]*FAIL %s" % result_info[1]
                                        result_str += "[assert]" + case_result + tmp_msg + "\n"
                                    else:
                                        parsed_flag = True
                            if not result_list:
                                if parsed_flag:
                                    i_case['result'] = STR_FAIL
                                    result_str = "[assert]FAIL[message]*FAIL %s" % result_info[1]
                                else:
                                    i_case['result'] = STR_BLOCK
                                    i_case['stdout'] = "[Message]Timeout"
                            else:
                                if "FAIL" in result_list:
                                    i_case['result'] = STR_FAIL
                                else:
                                    i_case['result'] = STR_PASS
                            i_case['stdout'] = result_str.strip("\n")
                        else:
                            i_case['result'] = STR_BLOCK
                            i_case['stdout'] = "[Message]Timeout"
                except Exception, e:
#.........这里部分代码省略.........
开发者ID:testkit,项目名称:testkit-lite,代码行数:103,代码来源:test_executer.py

示例9: parse_page

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]
    def parse_page(self, link, browser):

        router = ["TL-WR","TL-R1","TD-W8","TL-MR","TL-WV","TL-WD","TL-ER","TL-TR","TL-H2","TL-CP","TL-PW"]

        modem = ["TD-89","TD-86","TD-88","TD-87"]

        camera = ["TL-SC"]

        switch = ["TL-SG","TL-SL"]

        ap = ["TL-WA","TL-AC","TL-AP"]

        printing_server = ["TL-PS"]

        browser.implicitly_wait(TplinkSpider.timeout)
        browser.set_page_load_timeout(TplinkSpider.timeout)
        try:
            browser.get(link)
        except TimeoutException:
            pass

        element = WebDriverWait(browser, TplinkSpider.timeout).until(
            EC.presence_of_element_located((By.CLASS_NAME, "download")))
        lines = element.find_elements_by_xpath(
            "table/tbody/tr[position()<last()]")
        item = BasicItem()
        item["Manufacturer"] = "Tplink"
        #item["Info"] = {}
        item["ProductVersion"]=""
        item["PackedTime"]=""
        item["ProductClass"]=""
        #item["Info"]["Size"]=""
        item["ProductModel"]=""
        item["Description"]=""


        for l in lines:
            key = l.find_element_by_xpath("td[1]").text.lstrip()
            val = l.find_element_by_xpath("td[2]")
            if key == u"立即下载":
                item["URL"] = val.find_element_by_xpath(
                    "a").get_attribute("href")
                #item["Rawlink"] = item["Link"]
                item["FirmwareName"] = item["URL"].rsplit("/", 1).pop()

                reg = re.compile(r'20[0-1][0-9][0-1][0-9][0-3][0-9]')
                regs = reg.search(item["FirmwareName"])
                if regs !=None:
                        item["PackedTime"] = regs.group()
                if regs ==None:
                        item["PackedTime"] = ""
            elif key == u"软件名称":
                b = val.text

                try:
                    a = b


                    m = a.replace(re.split(r'\w*', a)[-1], "").split(" ")
                    item['ProductModel'] = m[0]

                    c= re.search(r'V[0-9]+.[0-9]',a).group()  #m[-1].split("_")[0]
                    if c[-2] == "_":
                        cc = c.split("_")
                        item['ProductVersion'] = cc[0]
                    else:
                        item['ProductVersion'] = c





                    #item["Published"] = m[-1].split("_")[-1]
                    #item["Info"]['Published'] = m[-1].split("_")[-1]
                    #a = item["Published"]
                    #a = a.strip()
                                #print a
                                #print"#####################################################"

                    #try:
                     #   array=time.strptime(a,u"%y%m%d")
                      #  item["Published"] = time.strftime("%Y-%m-%d",array)
                    #except Exception, e:
                                    #print"**********************format errror***********************"
                     #   print e
                                    #print "************ss"

                except:
                    pass

            elif key == u"软件简介":
                item["Description"] = val.text

            #elif key == u"软件大小":
             #   item["Info"]['Size'] = val.text

            elif key == u"上传日期":
                item["PublishTime"] = val.text

                a = item["PublishTime"]
#.........这里部分代码省略.........
开发者ID:ilovepp,项目名称:firminsight,代码行数:103,代码来源:tplinkSpider.py

示例10: get_teachers

# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_xpath [as 别名]

#.........这里部分代码省略.........

					p_e= a_e.xpath("../following-sibling::p[1]")
					dirty_data = etree.tostring(p_e[0])
					matching =  re.search('(n: |160;)(\d{4})',dirty_data)
					if matching is not  None:
						extension= matching.group(2)
					
					if not name=='':
						t= Teacher(name= name, email=email, rangekind= rangekind, extension=extension, webpage= url_e)
						teachers.append(t)

		elif patternG03[0] in d.name or patternG03[1] in d.name or patternG03[2] in d.name:
			print unique_teachers_url[link];
			br.follow_link(unique_teachers_url[link]);
			root = html.fromstring(br.response().read())
			iframe_e = root.xpath("//iframe[contains(@src, 'academia.uniandes.edu.co/WebAcademy/showFaculties')]")[0]
			aca_url=iframe_e.get("src");
			print aca_url

			from selenium import webdriver
			from selenium.webdriver.common.by import By
			from selenium.webdriver.support.ui import WebDriverWait
			from selenium.webdriver.support import expected_conditions as EC
			from selenium.common.exceptions import TimeoutException

			#browser = webdriver.Firefox()
			browser = webdriver.PhantomJS()
			#browser = webdriver.Remote(desired_capabilities={'browserName': 'htmlunit', 'javascriptEnabled': True, 'platform': 'ANY', 'version': '', 'setThrowExceptionOnScriptError': True})
			response= browser.get(aca_url)
			delay = 60 # seconds
			try:
				e= WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, "x-auto-6")))
				print "Page is ready!"
				teachers_e= e.find_elements_by_xpath("//div[contains(@class, 'x-grid3-col-idInfoFacultyColumn')]")
				for t_e in teachers_e:
					name=""
					email=""
					rangekind=""
					extension=""
					extension=""
					webpage=""

					inner_html = t_e.get_attribute('innerHTML')
					matches =  list(re.finditer('</b>(.*?)<br>', inner_html))
					name= matches[1].group(1) + ' ' +  matches[0].group(1)
					email= matches[2].group(1)

					matching =  re.search(ur'n: </b>(\d{4}( - \d{4})?)<br>',inner_html)
					if matching is not  None:
						extension= matching.group(1)

					matching =  re.search(ur'<b>(Profesor(.*?))</b>',inner_html)
					if matching is not  None:
						rangekind= matching.group(1)
					if rangekind=="":
						rangekind="Pendiente por asignar"
					
					t= Teacher(name= name, email=email, rangekind= rangekind, extension=extension)
					teachers.append(t)

			except TimeoutException:
				print "Loading took too much time!"
			

		elif patternG04[0] in d.name:
			print "ARTE"
开发者ID:jtuburon,项目名称:bigdata,代码行数:70,代码来源:views.py


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