无法使用 selenium webdriver 进行鼠标悬停操作

Not able to do mouse over operation using selenium webdriver

代码如下

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();

我想点击 'my accounts' 或任何其他链接。 Kindle 告诉我怎么做

试试

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);

@kavya

请尝试此代码。我认为您无法在密码文本框中输入密码。

密码:

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

菜单:

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();

希望这会奏效