简体   繁体   English

如何在 Selenium IDE 中自动执行“右键单击”事件并在新窗口/选项卡中打开链接

[英]How To Automate "Right click" event in Selenium IDE and opening the link in New window/tab

I am using Selenium IDE for a google search scenario.我将 Selenium IDE 用于谷歌搜索场景。

1 open google

2 then  type "india" and click on the search button

3 then go to any link and right clicking on that link 
  and open that link in new tab or window 

what i have done till now is到目前为止我所做的是

<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>id=gbqfq</td>
    <td>india</td>
</tr>
<tr>
    <td>click</td>
    <td>id=gbqfb</td>
    <td></td>
</tr>
<tr>
    <td>contextMenu</td>
    <td>//*[@id='rso']/li[3]/div/h3/a</td>
    <td> </td>
</tr>

What i am not able to do is : right click on the link and then open that link in new window.我不能做的是:右键单击链接,然后在新窗口中打开该链接。

can anyone please suggest what need to do .任何人都可以请建议需要做什么。

"right click on the link and then open that link in new window" this is the browser feature not the page feature.. that why you not able to record it in IDE. “右键单击链接,然后在新窗口中打开该链接”这是浏览器功能而不是页面功能..这就是您无法在 IDE 中记录它的原因。

If you wanna know about recording right click, try click here如果您想了解录制右键单击,请尝试单击此处

You can Press Ctrl key and click on the link so that it gets opened in a new tab.您可以按 Ctrl 键并单击链接,以便在新选项卡中打开它。

For using control key in Selenium IDE use the below keywords.要在 Selenium IDE 中使用控制键,请使用以下关键字。

controlKeyDown ( ) 

//code for clicking the link

controlKeyUp ( ) 

您可以获取该链接的 href 属性,然后使用 openWindow() 命令在新窗口中打开它

Following opens the URL in a new tab, if you've configured Firefox to open new tabs instead of new windows.如果您已将 Firefox 配置为打开新选项卡而不是新窗口,则以下会在新选项卡中打开 URL。

storeAttribute | link-locator-here | myURLvariableName |
getEval | window.open( storedVars.myURLvariableName, '_blank' /* or tab target name*/ ); |

After spending a couple of days for research, I finally found the way to simulate Right-click in Selenium IDE through the execute script command:经过几天的研究,终于找到了在Selenium IDE中通过execute script命令模拟右键的方法:

const el = document.querySelector('CSS_SELECTOR_GOES_HERE');

const eventContextMenu = new MouseEvent('contextmenu', {
    bubbles: true,
});

el.dispatchEvent(eventContextMenu);

The trick here is that bubbles: true is required param.这里的诀窍是bubbles: true是必需的参数。

PS: Link to original answer in GitHub thread . PS: 链接到 GitHub 线程中的原始答案

在此处输入图像描述

暂无
暂无

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

相关问题 如何在Selenium IDE中处理新的窗口选项卡? - How to handle a new window tab in selenium IDE? Selenium IDE:无法自动执行按钮上的单击事件 - Selenium IDE : Not able to automate click event on button 通过右键单击并选择“在新选项卡中打开链接”在新选项卡中打开链接不起作用(Selenium) - Opening a link in a new tab by right clicking and selecting “Open link in new tab” is not working (Selenium) 如何右键单击链接并使用 Selenium 至 Java 在新选项卡中打开链接 - How to right click on a link and open the link in a new tab using Selenium through Java 如何使用 Control + Click of Selenium Webdriver 在同一窗口的新选项卡中的主选项卡中打开嵌入在 webelement 中的链接 - How to open a link embeded in a webelement with in the main tab, in a new tab of the same window using Control + Click of Selenium Webdriver Selenium Python右键单击“在新窗口中打开链接”-(Windows 7) - Selenium Python right click “Open link in new Window” - (Windows 7) Selenium IDE:在新选项卡中打开并将焦点切换到新选项卡不起作用 - Selenium IDE:Opening in new tab and shift focus to new tab not working 如何自动执行iframe中的硒离子点击操作? - How to automate iframe click in selenium-ide? 如何在Selenium IDE中自动化鼠标滚动事件 - How to Automate Mouse scrolling event in Selenium IDE 使用Selenium IDE在新标签页中打开链接 - Open a link in new tab using Selenium IDE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM