0
私は簡単なPHP WebアプリケーションをテストするためにJavaでSeleniumテストを書いています。それの多くはフィールドを埋めることです。セレン元素が目に見えないエラー - 定期的な発生
私が続けて2回(またはそれ以上)のテストを実行しようとすると、私は次のエラーを取得する:
org.openqa.selenium.ElementNotVisibleException:
Session ID: ef10680c-429b-4312-9d69-41496e7dce6a
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at com.midamcorp.insurance.TesterNGTest.test(TesterNGTest.java:83)
文は正しい要素が見えない - それがない理由問題があります可視。開始時に、この要素はJavascriptによって隠されています。ただし、リンク要素をクリックするだけで簡単に表示できます。私はこの「クリック」を私のテストでも実行します。
@BeforeClass
public static void setUpClass() throws Exception {
System.setProperty("webdriver.gecko.driver","C://geckodriver/geckodriver.exe");
driver = new FirefoxDriver();
driver.get(BASE);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
// login
driver.findElement(By.id("ssn")).clear();
driver.findElement(By.id("ssn")).sendKeys("user");
driver.findElement(By.id("user")).clear();
driver.findElement(By.id("user")).sendKeys("pass");
driver.findElement(By.name("login")).click();
// insurance screen
driver.findElement(By.name("phone")).clear();
driver.findElement(By.id("phone")).sendKeys("phone");
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys("email");
driver.findElement(By.id("empSSN")).sendKeys("ssn");
driver.findElement(By.id("address")).clear();
driver.findElement(By.id("address")).sendKeys("address");
driver.findElement(By.id("city")).clear();
driver.findElement(By.id("city")).sendKeys("city");
new Select(driver.findElement(By.id("state"))).selectByVisibleText("Missouri");
driver.findElement(By.id("zip")).sendKeys("63780");
driver.findElement(By.id("genderFemale")).click();
if(!(driver.findElement(By.cssSelector("input[type='checkbox")).isSelected())) { driver.findElement(By.cssSelector("input[type='checkbox")).click(); }
driver.findElement(By.cssSelector("input[value='1']")).click();
new Select(driver.findElement(By.name("employmentLocation"))).selectByVisibleText("Central Office");
driver.findElement(By.cssSelector("input.btn.btn-primary")).click();
// enrollment
// the code below is supposed to see if the container for the radio buttons is hidden, if so, click the link to display them
if(!(driver.findElement(By.id("healthOnly")).isDisplayed())) {
driver.findElement(By.cssSelector("a[href='#healthOnly']")).click();
}
// the line below is the one that throws the error; the link noted above is not being clicked and thus the container with the radio buttons remains hidden
List<WebElement> insuranceOptions = driver.findElements(By.cssSelector("#healthOnly input[type='radio']"));
insuranceOptions.get(rand.nextInt(insuranceOptions.size() - 1)).click();
insuranceOptions = driver.findElements(By.cssSelector("input[name='visionID']"));
insuranceOptions.get(rand.nextInt(insuranceOptions.size() - 1)).click();
私のシンプルなJavascript/jQueryは、要素の表示と非表示を切り替えます。私が手動でクリックすると、期待どおりに動作します。
$(".insuranceOptionsToggle").click(function(e){
e.preventDefault();
$($(this).attr("href")).toggle();
$(this).toggleClass("active");
});
お返事ありがとうございます。私はセレンの新しいですが、私は暗黙のうちにコールがこれを妨げたと思いましたか?また、私の投稿からは明らかではないかもしれませんが、クリックされた.insuranceOptionsToggle要素(リンク)は常に表示されます(実際には、通常のユーザー操作中に呼び出される関数です)。このリンクをクリックすると、ラジオボタンを格納するdiv要素が表示されます。それは常に表示されていないdivです。再度、感謝します。 – KellyMarchewa
私はこれを証明する情報を見つけることができませんが、私は暗黙の待ちは、要素の存在と可視性を待つかもしれないと思います。私は、あなたが 'ElementNotVisibleException'を取得していて、' NoSuchElementException'を取得していないという事実がこれを示していると思います。あなたは 'WebDriverWait'を使用してここでの可視性を待って問題が解決するかどうか確認することができます。注:暗黙的および明示的な待機を一緒に使用しないでください。これは、ドキュメントごとに信頼できない結果をもたらします。 http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp – JeffC