简体   繁体   English

无法访问srcdoc iframe中的按钮?

[英]Can't access button inside srcdoc iframe?

I have an <iframe> loaded using a srcdoc attribute, not from src . 我有一个使用srcdoc属性而不是从src加载的<iframe> I want to click the button using Watir-WebDriver, but I can't figure out how to locate the button, even in an <iframe> with an id attribute. 我想使用Watir-WebDriver单击按钮,但是即使在具有id属性的<iframe> ,我也无法弄清楚如何找到该按钮。

Is it possible to locate elements in an <iframe> loaded from srcdoc ? 是否可以在从srcdoc加载的<iframe>定位元素?

<html>
    <body>
        <div id="iphone">
            <iframe id='ip1' srcdoc="<%= Nokogiri::HTML(my html code)%>"></iframe>
        </div>
    </body>
</html>

If the button you are attempting to click is within an iframe, you will need to make WebDriver switch focus to that iframe first. 如果您要单击的按钮在iframe中,则需要首先使WebDriver切换焦点到该iframe。

This is because the content within an iframe is not visible to WebDriver unless it is currently focused on that iframe. 这是因为iDrive中的内容对于WebDriver而言是不可见的,除非当前专注于该iframe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM