John
John

Reputation: 700

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.

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 .

Upvotes: 3

Views: 9847

Answers (5)

YUzhva
YUzhva

Reputation: 333

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:

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.

P.S: Link to original answer in GitHub thread.

enter image description here

Upvotes: 0

Peter Kehl
Peter Kehl

Reputation: 87

Following opens the URL in a new tab, if you've configured Firefox to open new tabs instead of new windows.

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

Upvotes: 0

Abhishek_Mishra
Abhishek_Mishra

Reputation: 4621

you can get the href attribute of that link and then open it in a new window by using openWindow() command.

Upvotes: 0

HemChe
HemChe

Reputation: 2337

You can Press Ctrl key and click on the link so that it gets opened in a new tab.

For using control key in Selenium IDE use the below keywords.

controlKeyDown ( ) 

//code for clicking the link

controlKeyUp ( ) 

Upvotes: 0

cL83
cL83

Reputation: 489

"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.

If you wanna know about recording right click, try click here

Upvotes: 0

Related Questions