近在對(duì)testlink系統(tǒng)上做點(diǎn)東西,在定位部分元素時(shí)折騰了一段時(shí)間才搞定,特此記錄
如下圖
要定位紅色框部分
一:先分析testlink頁(yè)面結(jié)構(gòu),如下
如二個(gè)frame組成,一個(gè)是titlebar另一個(gè)是主frame,所以在定位時(shí)必須切換才能定位到相關(guān)元素
<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>
二、定位測(cè)試產(chǎn)品并選擇對(duì)應(yīng)產(chǎn)品內(nèi)容:
browser.switch_to_frame('titlebar') #切換到iframe為titlebar上
print browser.current_url
#browser.find_element_by_name('testproject').click()
#遍歷下拉框并選擇需要的項(xiàng)目
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='執(zhí)行']").click() #執(zhí)行用例