如何在 QTP 中通过 xpath 从 iframe 查找元素

How to find element by xpath from iframe in QTP

本文关键字:xpath iframe 查找 元素 QTP      更新时间:2023-09-26

我尝试在 QTP 中设置<input type="file" name="file007">值但是此元素处于iframe下,无法通过 XPath 获取它从页面:

<iframe id="file_007" src="javascript:''" style="position:absolute;width:0;height:0;border:0">
    #document
      <html>
       <head>
       </head>
          <body>
           <form action="/file/upload" method="POST" target="_self" enctype="multipart/form-data">
            <input name="files" type="text">
            <input type="hidden" name="name1" value="1">
            <input type="hidden" name="name2" value="2">
            <input type="hidden" name="name3" value="3">
            <input type="hidden" name="name4" value="4">
            <input type="hidden" name="name5" value="5">
            <input type="hidden" name="name6" value="6">
            <input type="hidden" name="name7" value="false">
            <input type="file" name="file007">
           </form>
    </body>
    </html>
    </iframe>

我通过//iframe[contains(@id, 'File')]找到了 iframe,但#documents中的元素不可见

如何在页面上找到此元素谢谢

你为什么使用 XPath?似乎 QTP 的默认对象标识应该适合您。

 Browser("title:=.*").Page("title:=.*").Frame("html id:=file_007").WebFile("name:= file007").Set "C:'file.txt"
如果您需要使用 XPath,

那么我认为 QTP 仅支持文档中的 XPath,因此您需要识别Frame(可选通过 XPath),然后在它下标识相对于其所有者的元素Frame