After right click a link how to select an option on right click menu

6,848 views
Skip to first unread message

pratika

unread,
Sep 28, 2012, 2:32:01 AM9/28/12
to webd...@googlegroups.com
I used following code

WebElement elementq = driver.findElement(By.xpath("//div[@id='component-1049']/div/a")); 
Actions builderq = new Actions(driver); 
Action rClick = builderq.contextClick(elementq).build(); 
rClick.perform();


Now how to select an option from right clicked menu

Manoj

unread,
Sep 28, 2012, 3:00:03 AM9/28/12
to webd...@googlegroups.com
Use sendkeys to pass the arrow up and down to select the value where u want to click and then click enter button using sendkeys .

WebElement elementq =driver.findElement(By.xpath("//div[@id='component-1049']/div/a")); 
Actions builderq = new Actions(driver); 
builderq.contextClick(elementq).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ENTER); 
builderq.build().perform();


--Manoj Hans

pratika

unread,
Sep 28, 2012, 7:14:40 AM9/28/12
to webd...@googlegroups.com
Thanks Manoj..........its working f9

Manoj

unread,
Sep 28, 2012, 7:34:28 AM9/28/12
to webd...@googlegroups.com
Glad to know that its working for u...

Mark Collin

unread,
Jun 5, 2013, 4:38:01 AM6/5/13
to webd...@googlegroups.com
What are you trying to do (i.e. why are you right clicking a link?)


On 03/06/2013 09:36, Sandeep Raja wrote:
Hi Manoj,

My requirement is to Right click and select an option in that, I have done scripts for RightClick, 
but my arrow keys are not working to select an item, So can you suggest any method to select the particular item or any method to move the mouse to the particular item and click

Thanks,
Sandeep
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sandeep R

unread,
Jun 5, 2013, 5:00:43 AM6/5/13
to webdriver
I need perform some action(ie. to open a side panel in a browser, you can think as I need to open a new tab or window). Im able to right click on a cell, and from that context menu I need to select an option to do the action(say open a new tab). I can use sendKeys, but the thing is, in the contextMenu, the options are dynamically comes, and cant be sure the option will always come as 2nd option in the rightclick menu. So I need to select an option with the option name itself. Pls suggest
Thanks,
Sandeep

Sandeep R


Manoj

unread,
Jun 6, 2013, 5:15:17 AM6/6/13
to webd...@googlegroups.com
Hi Sandeep,

There is no option to click dynamic context menu items but u can put some conditions to ensure that u r on right page after click on context menu option using sendkeys.




-- Manoj Hans

Sri

unread,
Mar 2, 2014, 7:44:58 PM3/2/14
to webd...@googlegroups.com
Hello...
How can i select second or third link after right click on a menu

Thanks in advance

Vvek

unread,
Mar 4, 2014, 12:28:40 AM3/4/14
to webd...@googlegroups.com
Hi Sri

     After the right click, you can simply use id, classname, or xpath ,.etc for click an element.

Srividya Attuluri

unread,
Mar 4, 2014, 12:36:00 AM3/4/14
to webd...@googlegroups.com
Hello Vivek,

My concern is just wanted to click on third link after right click.

Let me explain you scenario : after right click on a element we get like (Open a new page,open a new window,save a link)
like this out of that i am able to select first link not on the second link using following peace of code

element2 = oAction.context_click(element)
element2.send_keys(Keys.ARROW_UP).send_keys(Keys.ENTER).perform()


--
You received this message because you are subscribed to a topic in the Google Groups "webdriver" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/webdriver/ctB7p-nIjxI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to webdriver+...@googlegroups.com.

To post to this group, send email to webd...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Thanks&Regards,
Srividya.

Vivek Soundararajan

unread,
Mar 4, 2014, 12:46:51 AM3/4/14
to webd...@googlegroups.com
Srividya,

Why  do we need to use ARROW_UP or ARROW_DOWN Keys?, If we know the clickable element's xpath, we can easily click the element using driver.findElement(By.xpath(xpath expression)).click();
       
      

Austin

unread,
Mar 4, 2014, 2:57:14 AM3/4/14
to webd...@googlegroups.com

I would love for you to tell me the xpath to a browser RIGHT click menu element. Good luck.

 

//Austin

 

From: webd...@googlegroups.com [mailto:webd...@googlegroups.com] On Behalf Of Vivek Soundararajan
Sent: 4. mars 2014 06:47
To: webd...@googlegroups.com
Subject: Re: [webdriver] Re: After right click a link how to select an option on right click menu

 

Srividya,

 

Why  do we need to use ARROW_UP or ARROW_DOWN Keys?, If we know the clickable element's xpath, we can easily click the element using driver.findElement(By.xpath(xpath expression)).click();

       

      

On Tue, Mar 4, 2014 at 11:06 AM, Srividya Attuluri <srividya...@gmail.com> wrote:

 

--

You received this message because you are subscribed to the Google Groups "webdriver" group.

To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.

Srividya Attuluri

unread,
Mar 4, 2014, 10:20:45 AM3/4/14
to webd...@googlegroups.com
Hi Austin,

I dont want to pass the xpath of the clickable element but just wanted to select by using Arrow _up andc arrow down
after that wanted to move to next tab in the window Now i am able to click the element using arrowup and downbut  not able to click on next tab using window handles .

regards
sri

Austin

unread,
Mar 5, 2014, 3:42:22 AM3/5/14
to webd...@googlegroups.com

My reply was to the other guy (Vivek) replying that you should use xpath on a browser menu. You, of course, cant.

 

I think at this point you need to post the html behind that window with tabs so we can have a look at how to solve it. I do think you are overengineering it and the solution is easier then you think J but I don’t know anything about your site so I really need to see some html.

 

//Austin

 

From: webd...@googlegroups.com [mailto:webd...@googlegroups.com] On Behalf Of Srividya Attuluri
Sent: 4. mars 2014 16:21
To: webd...@googlegroups.com
Subject: Re: [webdriver] Re: After right click a link how to select an option on right click menu

 

Hi Austin,

I dont want to pass the xpath of the clickable element but just wanted to select by using Arrow _up andc arrow down

after that wanted to move to next tab in the window Now i am able to click the element using arrowup and downbut  not able to click on next tab using window handles .

regards

sri

 

On Mon, Mar 3, 2014 at 11:57 PM, Austin <tor...@hotmail.com> wrote:




--
Thanks&Regards,

Srividya.

Shivaji Ghadge

unread,
Apr 12, 2017, 2:20:46 AM4/12/17
to webdriver


On Friday, September 28, 2012 at 12:30:03 PM UTC+5:30, Manoj wrote:
Use sendkeys to pass the arrow up and down to select the value where u want to click and then click enter button using sendkeys .

WebElement elementq =driver.findElement(By.xpath("//div[@id='component-1049']/div/a")); 
Actions builderq = new Actions(driver); 
builderq.contextClick(elementq).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ENTER); 
builderq.build().perform();


--Manoj Hans

But what if I have to select fourth option from context menu by right clicking??

We can use builderq.contextClick(elementq).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ENTER);
but this will select only one arrow up value.
Reply all
Reply to author
Forward
0 new messages