Testlink定位实例

最近在对testlink系统上做点东西,在定位部分元素时折腾了一段时间才搞定,特此记录

如下图

要定位红色框部分

一:先分析testlink页面结构,如下

如二个frame组成,一个是titlebar另一个是主frame,所以在定位时必须切换才能定位到相关元素

<frameset rows="70,*" frameborder="0" framespacing="0">
    <frame src="lib/general/navBar.php?tproject_id=0&tplan_id=0&updateMainPage=1" name="titlebar" scrolling="no" noresize="noresize" />
    <frame src="lib/general/mainPage.php" scrolling='auto' name='mainframe' />
    <noframes>
        <body>TestLink required a frames supporting browser.</body>
    </noframes>
</frameset>

二、定位测试产品并选择对应产品内容:

    browser.switch_to_frame('titlebar')  #切换到iframe为titlebar上
    print browser.current_url
    #browser.find_element_by_name('testproject').click()
    #遍历下拉框并选择需要的项目
    select = browser.find_element_by_name("testproject")
    allOptions = select.find_elements_by_tag_name("option")
    
    for option in allOptions:
        print "Value is: " + option.get_attribute("value")
        print "Text is:" +option.text
        if testconfig['testprojectid'] in option.text:
            option.click()
            break
    time.sleep(1)
    browser.find_element_by_xpath("//img[@title='执行']").click() #执行用例

三、定位测试计划时一直定位不出来,头痛,先记录,看有没有大神指点

<div class="chosen-container chosen-container-single" style=" 85%;" title=""><a tabindex="-1" class="chosen-single"><span>第三轮测试</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off"></div><ul class="chosen-results"><li data-option-array-index="0" style="" class="active-result">
                            xxxx
                     </li><li data-option-array-index="1" style="" class="active-result">
                             xxxx
                     </li><li data-option-array-index="2" style="" class="active-result">
                             Ixxxx
                     </li><li data-option-array-index="3" style="" class="active-result">
                             第一轮测试
                     </li><li data-option-array-index="4" style="" class="active-result result-selected">
                             第三轮测试
                     </li><li data-option-array-index="5" style="" class="active-result">
                             第五轮测试
                     </li><li data-option-array-index="6" style="" class="active-result">
                             第四轮测试
                     </li></ul></div></div>

先将写的部分代码帖出:

#定位测试计划并选用
browser.switch_to_default_content()
browser.switch_to_frame('mainframe')
print browser.current_url
print testconfig['testplan']
browser.find_element_by_xpath("//div[contains(@class,'chosen-c')]").click()
time.sleep(1)
browser.find_element_by_link_text('IOS_D10V100_rc4')-----这里有问题
#drop_down.find_element_by_link_text('IOS_D10V100_rc4')
#browser.find_element_by_name('testplan')
#Select(browser.find_element_by_name('testplan')).select_by_visible_text(testconfig['testplan'])
原文地址:https://www.cnblogs.com/landhu/p/4956348.html