python+selenium 元素定位--iframe

1. 一般webdriver要操作页面元素需要在Top Window的状态下,如下:

2.当浏览器显示iframe时,用正常的元素定位是没有效果的,需要将页面装换到iframe下再对页面元素进行操作

driver.switch_to.frame("iframe")
driver.find_element_by_xpath(".//*[@id='detailForm']/div[3]/div/input").get_attribute("value")

3. 当使用driver.switch_to_frame()跳转iframe时,会被画斜线,证明这个方法已经不用了,需要用新的:driver.switch_to.frame()

猜你喜欢

转载自www.cnblogs.com/lanbing/p/9126179.html