【问题标题】:Python selenium iframe, #document and again iframePython selenium iframe、#document 和 iframe
【发布时间】:2017-03-12 18:36:11
【问题描述】:

我必须在代码底部获取那个 src

<html>
 <head>...</head>
 <body class>
  <div class="class1"....</div>
    <div class="class2"....</div>
     <section id=...>
       <div id="id1"...</div>
         <div id="id2"...</div>
           <iframe id="iframe" src= "almost" ...>
             #document
               <html>
                 <head>...</head>
                 <body>
                   <div id=".."</div>
                   <iframe id="iframe" src="thats what I want" /iframe>

我可以使用以下代码“几乎”获得第一个 iframe src:

 elem = driver.find_element_by_xpath("//div[@id='id2']/iframe").get_attribute('src')

尝试通过代码获取botton src:

iframe = driver.find_elements_by_tag_name("iframe")[0]
driver.switch_to_frame(iframe)

element = driver.find_element_by_xpath("//iframe").get_attribute('src')
print element

但我只收到验证码错误,我不是人类,所以我认为#document 和 iframe 内部有问题

【问题讨论】:

    标签: python selenium iframe


    【解决方案1】:

    我相信你会写

    driver.find_element_by_xpath("//iframe[2]").get_attribute('src')
    

    找到第二个iframe的src属性,虽然我从来没有遇到过这种情况。希望这会有所帮助!

    【讨论】:

    • 抱歉,我从未遇到过嵌套 iframe,所以我认为这是它们特有的一些特性。
    • 我在第一篇文章中的代码正在运行,经过多次尝试后验证码出现问题:)
    【解决方案2】:

    我的代码正常,验证码有问题

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 2020-04-01
      • 1970-01-01
      • 2022-01-09
      • 2017-03-28
      • 2017-12-03
      • 2021-09-10
      • 2011-11-23
      • 2017-11-26
      相关资源
      最近更新 更多