kavya February 2016

Not able to do mouse over operation using selenium webdriver

Below is the code

WebDriver dr= new ChromeDriver();
dr.get("http://obsessory.com/");
dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[1]/a")).click();
dr.findElement(By.id("email")).sendKeys("username@gmail.com");
dr.findElement(By.name("LoginForm[password]")).sendKeys("password");
dr.findElement(By.xpath(".//[@id='signIn']/div[2]/div[3]/div[3]/input")).click();
Actions action = new Actions(dr);
WebElement we =  dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).moveToElement(dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"))).click().build().perform();

I wanted to click on 'my accounts' or any of those other links. Kindle tell me how to do that

Answers


Sanjay Bhimani February 2016

Try with

Actions action= new Actions(dr);
WebElement we =  dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).perform();
By locator = By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a");
dr.click(locator);


Pratyush08 February 2016

@kavya

Please try this code. I think you are not able to type password in password textbox.

For password:

dr.findElement(By.xpath("(//input[@id='email'])[2]")).sendKeys("obsessory");

For Menu:

WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a"));
WebElement ve = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"));

Actions act = new Actions(dr);
act.moveToElement(we).click(ve).perform();

Hope this will work

Post Status

Asked in February 2016
Viewed 3,446 times
Voted 6
Answered 2 times

Search




Leave an answer