2017-12-26 21 views
-1

コード:I getException "メイン" org.openqa.selenium.ElementNotInteractableException

WebElement betting = driver.findElement(By.id("flex-menu")); 
     List<WebElement> hallo = betting.findElements(By.xpath("//*[@id='flex-menu']//ul//li//a")); 

      System.out.println(hallo.get(0).getText()); 

      hallo.get(0).click(); 

エラーマッサージ:スレッドで

例外 "メイン" org.openqa.selenium.ElementNotInteractableException:

セッションID:0で sun.reflect.NativeConstructorAccessorImpl.newInstance0(ネイティブメソッド) で4bfaaf77-6275-4ffc-a8d7-b24b70f3acca java.lang.reflect.Constructor.newInstanceで sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) (Constructor.java:422)でsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) でorg.openqa.selenium.remote.http.W3CHttpResponseCodec.createException org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)で(W3CHttpResponseCodec.java:187) におけるORG .openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute (HttpCommandExecutor.java:164) でorg.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601で) でorg.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279) でorg.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83) Aufgabe1.Main.mainで(Main.java:41)

このコードで何が問題になっていますか?私はクリックできませんが、要素が見つかりました。

+0

[Selenium WebDriverの可能な複製は "スレッドで例外が発生しました"メイン "org.openqa.selenium.ElementNotInteractableException:要素が表示されない"エラー(https://stackoverflow.com/questions/44690971/selenium-webdriver-throws -exception-in-thread-main-org-openqa-selenium-elemen) – DebanjanB

答えて

1

2つの理由が考えられます。

1)ボタンの要素は表示されていますが、クリックできません。その場合、待機状態を使用します。

WebDriverWait myWaitVar = new WebDriverWait(driver,20); 
WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(betting.findElements(By.xpath("//*[@id='flex-menu']//ul//li//a")).get(0))); 
el.click(); 

2)要素が隠されている場合/他のいくつかの要素が重なっ In Selenium Webdriver, ExpectedCondition.elementToBeClickable is not waiting until the progress bar disappears

0

にJavascriptExecutor

WebDriverWait myWaitVar = new WebDriverWait(driver,20); 
    WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(betting.findElements(By.xpath("//*[@id='flex-menu']//ul//li//a")).get(0))); 
((JavascriptExecutor)driver).executeScript("arguments[0].click()", el); 

詳しい情報が提供されていますを使用することをあなたがしようとしている要素が隠しているためであること/暗黙の待機条件が必要です。 .enable()関数を使用して、暗黙的な明示的な待機条件を実装し、.click()関数を使用しようとします。

関連する問題