【问题标题】:Switch to Frame by STYLE?按样式切换到框架?
【发布时间】:2016-05-04 20:58:50
【问题描述】:

我正在尝试切换到允许我输入一些单词的框架。

HTML:

 <iframe style="height: 170px; width: 407px;">
   #document
    <html webdriver="true">
       <head></head>
      <body>
           <br _editor_node="TRUE"</br>

  </body>
  </html>
  </iframe>

我尝试的第一个代码:

driver.switch_to_frame(driver.find_element_by_tag_name('iframe'))
driver.find_element_by_css_selector('br[_moz_editor_bogus_node="TRUE"]').send_keys('hi')

我尝试的第二个代码:

for handle in driver.window_handles:
        driver.switch_to.window(handle)

driver.switch_to_frame(driver.find_element_by_tag_name('iframe'))
driver.find_element_by_css_selector('br[_moz_editor_bogus_node="TRUE"]')

我的错误:

NoSuchElementException:消息:无法找到元素:{“method”:“css 选择器","选择器":"br[_moz_editor_bogus_node=\"TRUE\"]"} 堆栈跟踪:

有没有办法按样式切换到框架?

这不起作用

driver.switch_to_frame(driver.find_element_by_css_selector('iframe[style="height:.177px;.width.407px;"]'))

【问题讨论】:

    标签: python html css selenium


    【解决方案1】:

    根据您提供的内容,最合乎逻辑的方法是获取其中包含所需元素的 iframe 元素:

    frame = driver.find_element_by_xpath('//iframe[br[@_moz_editor_bogus_node="TRUE"]]')
    driver.switch_to.frame(frame)
    

    【讨论】:

    • 你的意思是css_selector还是xpath?什么是 css_xpath?
    • @royalblue 哎呀 :) 我想我不应该同时做 10 件事,已修复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多