python---悬浮框,嵌套

'''
方法:
  switch_to.frame():将当前定位的主题切换为iframe表单的内嵌页面,适用于:表单嵌套:frame/iframe
 定位“找论坛”下的“二手车”
'''
#导包
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
#浏览器,网址:爱卡
dr=webdriver.Chrome()
dr.get("https://www.xcar.com.cn/")
#找论坛
one=dr.find_element_by_xpath("//*[@id='totop']/div/div[1]/div[1]")
#鼠标悬浮在找论坛上
ActionChains(dr).move_to_element(one).perform()
time.sleep(3)
#通过switch_to.frame():方法切换到表单页,来定位表单中的元素
dr.switch_to.frame("daohang")
time.sleep(2)
#再次帝国为表单中的盒子,只有定位到盒子之后才能找到盒子里元素
dr.find_element_by_xpath("//*[@id='box1']")
time.sleep(2)
#定位里面二手车
dr.find_element_by_xpath('//*[@id="fid_160"]').click()
time.sleep(2)
dr.quit()

  

原文地址:https://www.cnblogs.com/wsx123/p/14229852.html