Error while execution of program for right click | Selenium Forum
M
Posted on 23/03/2016
Hi Ashish,

As per described by you in 16.1 video I am writing code for scrolling of a webpage,right click and finding co-ordinates of link present under Health section of "times of india" site.There are following errors is coming:-

1.No Element found exception even I have copied absolute path from fire path.
2.The screen not scrolling down.
3.Not getting coordinate of link.
4.To right click on element as per your description I am using "sendKeys(Keys.chord(Keys.SHIFT,Keys.F10))" function but I am getting error like "The method chord(CharSequence[]) in the type Keys is not applicable for the arguments (Keys, Keys)".

I think these errors coming due to more page loading timing but not sure.Could you please help me to remove these issues.I have attached screenshot for your reference. Thanks in advance.

Code-
import java.awt.RenderingHints.Key;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.internal.EventFiringMouse;


public class MouseMovement {
/*Program for mouse movement and right click of mouse
*
*/

public static void main(String[] args) {
WebDriver web_driver = new FirefoxDriver();
EventFiringWebDriver driver= new EventFiringWebDriver(web_driver);//Here we have to use driver of EventDrivenDriver and its responsible for calling listener whenever some action is perform
MyListener myListener= new MyListener();//Need to register our function to it
driver.register(myListener);
/*Here we want to scroll down in times of india page
* and right click on "Holi 2016: Protect yourself from toxic colours" link
* before right click we want to move mouse on this link
* selenium will do this thing but we will not able to see
*/

driver.get("http://timesofindia.com");
EventFiringMouse mouse= new EventFiringMouse(driver, myListener);
//Need to move mouse over a link
Locatable hoverItem= (Locatable) driver.findElement(By.xpath("html/body/div[1]/div[5]/div/div[8]/div[13]/ul[1]/li[1]/h3/a"));

Coordinates c= hoverItem.getCoordinates();//Here we are extracting the element's co-ordiante

try{
mouse.mouseMove(c);//while using this command its mandatory to give in try,catch to catch error when it will comes during mouse movement

}catch(Exception e1){

}
/*right click is combination of shift and F10
*
*/

//code for right click
driver.findElement(By.xpath("html/body/div[1]/div[5]/div/div[8]/div[13]/ul[1]/li[1]/h3/a")).sendKeys(Keys.chord(Keys.SHIFT,Keys.F10));//To right click on the link
//Code for coordinate
Point p= driver.findElement(By.xpath("html/body/div[1]/div[5]/div/div[8]/div[13]/ul[1]/li[1]/h3/a")).getLocation();//To determine coordiante of link
System.out.println(p.x);
System.out.println(p.y);

}

}

M
Replied on 25/03/2016

[quote:2p5vx35i]1.No Element found exception even I have copied absolute path from fire path.[/quote:2p5vx35i]

don't use absolute xpath use partial xpath. watch module 15.


M
Replied on 25/03/2016

[quote:64jkt1u8]4.To right click on element as per your description I am using "sendKeys(Keys.chord(Keys.SHIFT,Keys.F10))" function but I am getting error like "The method chord(CharSequence[]) in the type Keys is not applicable for the arguments (Keys, Keys)".
[/quote:64jkt1u8]

install java 7.