python之处理selenium中的frame框架切换问题


①iframe框架有name或者id属性值

driver.switch_to.frame('iframe-name-id')

②iframe框架没有name或者id属性值:采用xpath元素定位方式(使用iframe的其他属性)

例如:

代码如下:

xf = self.driver.find_element_by_xpath('//iframe[@allowtransparency="true"]')

driver.switch_to.frame(xf)

③跳出当前iframe

self.driver.switch_to.parent_frame()

④返回最外层iframe

driver.switch_to.default_content()

相关