python自動(dòng)化測(cè)試selenium定位frame及iframe示例
frame標(biāo)簽有frameset、frame、iframe三種,frameset和其它普通標(biāo)簽沒(méi)有區(qū)別,不會(huì)影響正常定位,而frame與iframe對(duì)selenium定位而言是一樣的。
Selenium有以下方法對(duì)frame進(jìn)行操作。
示例網(wǎng)站:http://sahitest.com/demo/framesTest.htm
示例腳本:
from selenium import webdriver from time import sleep class TestFrame(object): def setup(self): self.driver = webdriver.Chrome() self.driver.get("http://sahitest.com/demo/framesTest.htm") def test_frame(self): top = self.driver.find_element_by_name("top") # 切換到上面的frame self.driver.switch_to.frame(top) #點(diǎn)擊上面frame中的Link Test鏈接,打開新頁(yè)面 self.driver.find_element_by_xpath("/html/body/table/tbody/tr/td[1]/a[1]").click() #切換到主頁(yè)面 self.driver.switch_to.default_content() sleep(3) # 切換到下面的frame second = self.driver.find_element_by_xpath("/html/frameset/frame[2]") self.driver.switch_to.frame(second) # 點(diǎn)擊下面frame中的Form Test鏈接,打開新頁(yè)面 self.driver.find_element_by_xpath("/html/body/table/tbody/tr/td[1]/a[2]").click() sleep(2) self.driver.quit() if __name__ == '__main__': frame = TestFrame() frame.test_frame()
以上來(lái)自:極客時(shí)間課程:selenium自動(dòng)化測(cè)試課程學(xué)習(xí)總結(jié)。
以上就是python自動(dòng)化測(cè)試selenium定位frame及iframe示例的詳細(xì)內(nèi)容,更多關(guān)于selenium定位frame及iframe的資料請(qǐng)關(guān)注本站其它相關(guān)文章!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。