RE: How to click the option of the menu which the right click pop up?

currently ,I study selenium web driver and learn a lot of tips&tricks from your website page (http://www.toolsqa.com/), very helpful ,so thanks a lot. As a beginner , I met many problems ,I appreciate it if you can help me to solve this problem.
Here is the thing:
I want to right click specific download button when pop up menu, click the one of the options(such as save ,in Chinese character it’s “另存为” ). let me show you ,please see the picture as following:

RE: How to click the option of the menu which the right click pop up?


my problem is I can’t click the “save” option by webdriver,please help me. thanks in advance !!!
I also try some code from other guys, but doesn’t work at all.

Actions act = new Actions(driver);

WebElement link = driver.findElement(By.id("xpath"));

act.moveToElement(link).contextClick().sendKeys(Keys.ArrowsDown).build().perform();


please help !!!

Young Train Asked on September 10, 2014 in Selenium WebDriver.
Add Comment
3 Answers
Best answer

HI Young,

It is not possible through Selenium but this can be done using ROBOT class and AUTOIT it self. I have just tried it with ROBOT class and it worked for me.


public class Test {

private static WebDriver driver = null;

public static void main(String[] args) throws InterruptedException, AWTException {

driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.get("https://www.autoitscript.com/site/autoit/downloads/");

WebElement myElement = driver.findElement(By.xpath(".//*[@id='content-area']/div/table/tbody/tr[1]/td[2]/p/a/img"));

Actions oAction = new Actions(driver);

oAction.moveToElement(myElement);

Thread.sleep(1000);

// This will do a right click

oAction.contextClick(myElement).build().perform();

Robot robot = new Robot();

// This will bring the selection down one by one

robot.keyPress(KeyEvent.VK_DOWN);

Thread.sleep(1000);

robot.keyPress(KeyEvent.VK_DOWN);

Thread.sleep(1000);

robot.keyPress(KeyEvent.VK_DOWN);

Thread.sleep(1000);

robot.keyPress(KeyEvent.VK_DOWN);

Thread.sleep(1000);

robot.keyPress(KeyEvent.VK_DOWN);

Thread.sleep(1000);

// This is to release the down key, before this enter will not work

robot.keyRelease(KeyEvent.VK_DOWN);

Thread.sleep(1000);

robot.keyPress(KeyEvent.VK_ENTER);
}

Please do not forget to mark your question as ANSWERED.

Regards,
Lakshay Sharma

Professor Answered on September 12, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.