Yogiraj
Yogiraj

Reputation: 273

using contextclick in selenium webdriver

I'm trying to use ContextClick() method from selenium webdriver to right click on element and select the second option from context menu. this is my sample code here. when i execute this right click opetion doesnt happen on the element specified, no error message as well. I'm using selenium 3.4, tried for both firefox and chrome driver.

Any help on this much appreciated..!

driver = new FirefoxDriver();
driver.get("http://google.com"); 
driver.findElement(By.name("q")).sendKeys("London");

Actions action = new Actions(driver);
driver.findElement(By.xpath("//input[@value='Google Search']")).click();
action.contextClick(driver.findElement(By.xpath("//a[text()='Sign in']"))).build().perform();

Upvotes: 0

Views: 3581

Answers (1)

iamsankalp89
iamsankalp89

Reputation: 4739

this is known issue of Firefox and selenium jar 3.2 and above

See this issue links:

https://github.com/mozilla/geckodriver/issues/233 https://github.com/SeleniumHQ/selenium/issues/3348

When I tried it throw the Exception

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: mouseMoveTo

I have tried this code:

System.setProperty("webdriver.chrome.driver","E:/software and tools/chromedriver_win32/chromedriver.exe");
 WebDriver  driver = new ChromeDriver( );
 driver.get("http://google.com"); 
 driver.manage().window().maximize();
 driver.findElement(By.name("q")).sendKeys("London");
 driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
 WebElement ele= driver.findElement(By.xpath("//a[text()='Sign in']"));
 Actions action = new Actions(driver);
 action.moveToElement(ele);
 action.contextClick(ele).build().perform();

Also I modified your code as

driver.findElement(By.xpath("//input[@value='Google Search']")).click();

as this statement throw nosuchelementexception Exception as it is hiding, Try this code it works for me

Upvotes: 0

Related Questions