selenium 难定位元素、时间插件
-
關(guān)于frame:
1.?如果網(wǎng)頁存在iframe的話,傳統(tǒng)的定位有時(shí)候找不到元素,需要切換frame;
# 切換到leftFrame定位“測(cè)井設(shè)計(jì)”
driver.switch_to_frame("leftFrame")
driver.find_element_by_link_text(u"設(shè)計(jì)").click()
# 切換到rightFrame定位“設(shè)計(jì)”(先回到主內(nèi)容再次定位,否則二次定位認(rèn)為嵌套)
driver.switch_to_default_content()
driver.switch_to_frame("rightFrame")
driver.find_element_by_id("start").click()
?
2.有些插件用的也是frame,如時(shí)間插件
# 先定位到時(shí)間選擇框,點(diǎn)擊
driver.find_element_by_id("logmin").click()
#通過xpath定位frame
frames = driver.find_element_by_xpath("/html/body/div[2]/iframe")
#切換到frame
driver.switch_to_frame(frames)
# 選擇2017-1-5,通過xpath定位,點(diǎn)擊
driver.find_element_by_xpath(
"/html/body/div/div[3]/table/tbody/tr[2]/td[5]").click()
# 最后切換回原來和右邊的frame
driver.switch_to_default_content()
driver.switch_to_frame("rightFrame")
?
轉(zhuǎn)載于:https://www.cnblogs.com/zhaoyq/p/9921632.html
總結(jié)
以上是生活随笔為你收集整理的selenium 难定位元素、时间插件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 模拟测试
- 下一篇: zoj4062 Plants vs.