2017-08-26 55 views
0

工作,我已經寫代碼自動懸停鼠標操作: -操作類不硒3.5.2

Actions action=new Actions(driver); 
WebElement product=driver.findElement(By.xpath("//*[@id='Products']/em")); 
WebElement catalogue=driver.findElement(By.xpath("//*[text()='Master Catalog']")); 
Actions builder = new Actions(driver); 
Action mouseOverMenu = builder.moveToElement(product).build(); 
mouseOverMenu.perform(); 
Thread.sleep(3000L); 
catalogue.click(); 

我想首先懸停「產品」 webelement飄搖「產品」 webelement「目錄後, '出現並且想要點擊'目錄'webelement。

但是這個代碼拋出異常,下面,請提示: -

org.openqa.selenium.ElementNotInteractableException: 
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z' 
System info: host: 'DESKTOP-0HLH9L7', ip: '192.168.168.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111' 
Driver info: org.openqa.selenium.firefox.FirefoxDriver 
Capabilities [{moz:profile=C:\Users\lenovo\AppData\Local\Temp\rust_mozprofile.Vz7r3MDL9N0a, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=54.0.1, platformVersion=10.0, moz:processID=528, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}] 
Session ID: cc3875ef-61fd-422c-86cb-3647fbf03d93 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185) 
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120) 
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) 
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) 
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641) 
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275) 
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82) 
    at actionsClass.MoveTo.Moving(MoveTo.java:44) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:661) 
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869) 
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193) 
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 
    at org.testng.TestRunner.privateRun(TestRunner.java:744) 
    at org.testng.TestRunner.run(TestRunner.java:602) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:289) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) 
    at org.testng.TestNG.runSuites(TestNG.java:1144) 
    at org.testng.TestNG.run(TestNG.java:1115) 
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) 
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) 
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76) 
+0

放置隱式等待或顯式等待。 – iamsankalp89

+0

@ iamsankalp89: - 已添加隱式等待: - driver.manage()。timeouts()。implicitlyWait(50,TimeUnit.SECONDS);但它不起作用。 :( –

+0

嘗試更改瀏覽器,並嘗試使用最新的硒webdriver。大多確認是否行爲在所有瀏覽器上是否相同 –

回答

0

嘗試如下:

Actions builder = new Actions(driver); 
builder.moveToElement(product).moveToElement(catalogue).click().build().perform(); 

編輯1:

Actions act1 = new Actions(driver); 
Actions act2 = act1.moveToElement(product).build(); 
act2.moveToElement(catalogue).click().build().perform(); 

編輯2:

Actions act1 = new Actions(driver); 
Actions act2 = new Actions(driver); 
act1.moveToElement(product).build(); 
Thread.sleep(4000); //you can change this to explicit wait later 
act2.moveToElement(catalogue).click().build().perform(); 
+0

它不工作kushal,檢查此網址https://stackoverflow.com/questions/45911879/action-class -is-not-working-with-selenium-3-5-2 –

+0

@JainishKapadia:嘗試編輯部分 – kushal

+0

Kushal,我也嘗試過你的更新答案,但仍然面臨同樣的問題 –