Bimlesh
Bimlesh

Reputation: 281

Right click is not happening and element is getting clicked on the same tab

I have a Selenium script to execute the following steps:

  1. Launch the website - https://vusevapor.com/
  2. Hit "I am 21+" button
  3. Move to element devices.
  4. Right-click on ciro complete kit.

The issue is that the right-click menu remains as is, and the element is getting clicked on the same page.

Here is my code:

//website
driver.get("https://vusevapor.com/");

//clicking on i am 21+ button
driver.findElement(By.xpath("/html/body/aside/div[2]/div/div/div[2]/div/a[1]/span")).click();   

Thread.sleep(5000);
//xpath of devices menu

WebElement devices = driver.findElement(By.xpath("//*[@id=\"store.menu\"]/nav/ul/li[2]/a/span"));

//move to element devices

Actions act = new Actions(driver);

act.moveToElement(devices).build().perform();

Thread.sleep(3000);

//xpath of ciro complete kit

WebElement ciroKit = driver.findElement(By.xpath("//*[@id=\"store.menu\"]/nav/ul/li[2]/ul/li[2]/ul/li[1]/a/span"));


//right click on ciro complete kit 

//*****Issue********right click is happening but the element is getting clicked on the same tab and right click menu remains as is

act.contextClick(ciroKit).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

Upvotes: 0

Views: 38

Answers (1)

Amruta
Amruta

Reputation: 1166

try this: option 1:

act.contextClick(ciroKit).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();

option 2- Use Action and Robot class:

act.contextClick(ciroKit).build().perform();
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_ENTER);

Hope this helps.

Upvotes: 1

Related Questions