Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用selenium webdriver执行鼠标悬停操作_Java_Selenium_Selenium Chromedriver - Fatal编程技术网

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

Java 无法使用selenium webdriver执行鼠标悬停操作,java,selenium,selenium-chromedriver,Java,Selenium,Selenium Chromedriver,下面是代码 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[p

下面是代码

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();
我想点击“我的账户”或其他任何链接。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);
试一试

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);
@卡维亚

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

密码:

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();
希望这能奏效

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

密码:

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

希望这能起作用

您是否使用设置系统属性和chromedriver.exe创建了chromedriver?Ya。。我已经创建了首先保护您的id和密码,您已经在问题中发布了凭据。这是个坏习惯。对不起,我只使用Nook。@SanjayBhimani。在这种情况下没关系。密码太差了,我想没有人会接受它。您是否使用设置系统属性和chromedriver.exe创建了chromedriver?是的。。我已经创建了首先保护您的id和密码,您已经在问题中发布了凭据。这是个坏习惯。对不起,我只使用Nook。@SanjayBhimani。在这种情况下没关系。密码太差了,我想没人会接受。我已经试过了。但是我在线程“main”java.lang.ClassCastException中得到以下异常:org.openqa.selenium.chrome.ChromeDriver不能强制转换为org.openqa.selenium.interactions.Actionscode是正确的,只需使用显式thread.sleep等待并让我知道。我已经尝试过了。但是我在线程“main”java.lang.ClassCastException中得到以下异常:org.openqa.selenium.chrome.ChromeDriver不能强制转换为org.openqa.selenium.interactions.Actionscode是正确的,只需使用显式thread.sleep等待并让我知道。@kavya,试试这个,你正在尝试单击子菜单并为此单击(Webelement)事件存在,因此使用此选项,您的代码工作正常。@kavya,尝试此选项,您将尝试单击子菜单,并且此click(Webelement)事件存在,因此使用此选项,您的代码工作正常。