简体   繁体   English

如何在Selenium IDE中的iFrame中单击链接

[英]How to click on a link in an iFrame in selenium IDE

Hello Stackoverflow community, 您好Stackoverflow社区,

I am working with selenium IDE and I have the following problem: I have to move a web content within a web content Management System from one folder to another. 我正在使用Selenium IDE,但遇到以下问题:我必须将Web内容管理系统中的Web内容从一个文件夹移动到另一个文件夹。 Therefore I have to click on a "Select" button to specify a target folder, then an iframe opens up where I can navigate through the "tree structure" of the folders. 因此,我必须单击“选择”按钮以指定目标文件夹,然后打开iframe,在其中可以浏览文件夹的“树结构”。
The original page looks like this: 原始页面如下所示:
original page with "Select"-button 带有“选择”按钮的原始页面

在此处输入图片说明 The structure of the web content management system is as follows: Home Web内容管理系统的结构如下:主页

-Test(=Parent Folder):  
        -UniqueTitle  
        -UniqueTitle2  

Because the folder that I want to adress(UniqueTitle2) lies one hierarchy below my current folder(I am in UniqueTitle), I have to click on the parent Folder "TEST" to go one hierarchy back. 因为我要处理的文件夹(UniqueTitle2)位于当前文件夹下的一个层次结构中(我在UniqueTitle中),所以我必须单击父文件夹“ TEST”以返回一个层次结构。 This is a link to the "TEST"-folder. 这是“ TEST”文件夹的链接。

iframe where you can select the target folder iframe,您可以在其中选择目标文件夹

在此处输入图片说明

The problem is that on the original page below the iframe, the same Link to the "TEST"-folder exists as a breadcrumb. 问题是,在iframe下方的原始页面上,存在与“测试”文件夹相同的链接作为面包屑。 So if selenium clicks on the href link, it actually clicks the link on the original page, and not the one in the iframe. 因此,如果硒单击href链接,则实际上单击原始页面上的链接,而不是iframe中的链接。

I tried the following: to select the iframe: 我尝试了以下操作:选择iframe:

storeAttribute|css=iframe.dialog-iframe-node@id|iframeIDE
selectFrame|id=${iframeID}

to click on the link: 单击链接:

clickAndWait|link=TEST

clickAndWait|//a[contains(@href,'https://www.companyname.com/language/projectname/manage/maintenance/web-content-management[...]folderid=465576')]

Here is a HTML Snippet of the iframe: 这是iframe的HTML代码段:

<a href="https://www.companyname.com/language/projectname/manage/maintenance/web-content-management?p_p_id=15&amp;p_p_lifecycle=0&amp;p_p_state=pop_up&amp;p_p_mode=view&amp;_15_struts_action=%2Fjournal%2Fselect_folder&amp;_15_folderId=4655761" data-direction-right="true" data-folder-id="4655761">TEST</a>

How can I differentiate between these two, so my script will click within the iframe? 如何区分这两者,所以我的脚本会在iframe中单击?

Thank you in advance and let me know if you need more information. 预先谢谢您,如果需要更多信息,请告诉我。

you have two options: 您有两种选择:

1. don't use iframe, use div or section instead 1.不要使用iframe,而是使用div或section

using this approach, you have to move the code for file selection to the main page. 使用这种方法,您必须将用于文件选择的代码移动到主页。 use AJAX to populate the file list to the div. 使用AJAX将文件列表填充到div。 this approach is often called single page application, though you don't need to move everything to a single page, just the file selection codes. 这种方法通常称为单页应用程序,尽管您不需要将所有内容移动到单个页面,只需将文件选择代码移动到单个页面即可。

2. set allow-origin header of your iframe to your domain name or * 2.将iframe的allow-origin标头设置为您的域名或*

you should read about how to set this HTTP header. 您应该阅读有关如何设置此HTTP标头的信息。 here are some refs 这是一些参考

Probably duplicate of How to switch between frames in Selenium WebDriver using Java 可能与如何使用Java在Selenium WebDriver中的框架之间切换有关

First thing when you want to do something inside iframe is switch to it. 您想在iframe中做某事的第一件事就是切换到它。

WebDriver.SwitchTo().Frame(WebDriver.FindElement(By.Id("iframe")));

After that you can click on element. 之后,您可以单击元素。 When you want to back you can use: 当您想支持时,可以使用:

WebDriver.SwitchTo().DefaultContent();

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

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