zoukankan      html  css  js  c++  java
  • selenium+Python富文本框赋值

    ################################

    富文本框赋值
    富文本框是指<iframe></iframe>
    首先访问iframe
    再访问iframe中的contentWindow
    再访问body  
    使用innerText属性进行赋值(innterHtml)
    self.set_content(
    'content content') def set_content(self, text): js = "document.getElementById('content_ifr').contentWindow.document.body.innerText = '%s'" %(text) self.driver.execute_script(js)



    iframe1 = document.getElementsByTagName("iframe")[1]

    innertext = iframe1.contentWindow.document.body.innerText

    js = "document.getElementsByTagName("iframe")[1].contentWindow.document.body.innerText = '%s'" %(text)
    
    
    text = "我要提问一个问题"
    js = "document.getElementsByTagName('iframe')[1].contentWindow.document.body.innerText = '%s'" % (text)
    driver.execute_script(js)
     

    ####################################

    定位iframe
    
    # 1.有id,并且唯一,直接写id
    driver.switch_to_frame("x-URS-iframe")
    driver.switch_to.frame("x-URS-iframe")
    
    # 2.有name,并且唯一,直接写name
    driver.switch_to_frame("xxxx")
    driver.switch_to.frame("xxxx")
    
    # 3.无id,无name,先定位iframe元素
    iframe = driver.find_elements_by_tag_name("iframe")[0]
    driver.switch_to_frame(iframe)
    driver.switch_to.frame(iframe)
    
    # 4.通过index索引定位,(从0开始)
    driver.switch_to_frame(1) # 第二个
    
    # 使用iframe定位后需退出iframe
    # 退出iframe,再操作
    driver.switch_to_default_content() # 回到主页面
    driver.switch_to.default_content()

    ######################################

    ######################################

  • 相关阅读:
    「开始,DP专题」
    ZOJ3612 Median treap
    [HNOI2004]宠物收养所 treap
    SIRO Challenge 状态压缩 + DP 未解
    SPOJ3273 Order statistic set treap模板
    HNU2[I题]Omar Loves Candies 贪心
    HNU1[B题] DP,数位DP
    HNU1[F题] 栈模拟计算
    Node.js权威指南 (6)
    瘦下来之后你会遇见不一样的自己
  • 原文地址:https://www.cnblogs.com/andy0816/p/12717758.html
Copyright © 2011-2022 走看看