Excepción en hilo org.openqa.selenium.NoSuchElementException "principal": Cuando se trata de seleccionar un elemento de una selenio emergente usando

kaustubh:

Estoy intentando seleccionar crear un contacto en mi página web. Pero no soy capaz de seleccionar un usuario de un pop-up. Puede echar un vistazo aquí (este es mi sitio de prueba en la que estoy tratando de llevar a cabo el siguiente código).

Aquí está mi escritura de la prueba:

driver.get("http://automation.cloudaccess.host/administrator/index.php?option=com_contact&view=contacts");
driver.findElement(By.id("mod-login-username")).sendKeys("admin");
driver.findElement(By.id("mod-login-password")).sendKeys("admin@123");
driver.findElement(By.id("mod-login-password")).submit();
driver.findElement(By.xpath("//button[@onclick=\"Joomla.submitbutton('contact.add');\"]")).click();
driver.findElement(By.id("jform_name")).sendKeys("James");
driver.findElement(By.xpath("//div[@class='input-append']/a")).click();
driver.switchTo().frame("field-user-modal");
driver.findElement(By.id("filter_search")).sendKeys("admin");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.findElement(By.linkText("admin")).click();        
driver.findElement(By.xpath("//button[@onclick=\"Joomla.submitbutton('contact.save');\"]")).click();

Aquí está el error que estoy recibiendo:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"filter_search"}
  (Session info: chrome=66.0.3359.181)
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.15.0-24-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'vowellt4', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-24-generic', java.version: '1.8.0_171'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565383 (76257d1ab79276..., userDataDir: /tmp/.org.chromium.Chromium...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.181, webStorageEnabled: true}
Session ID: b3b7fc635039d93fe22d661995bb69a3
*** Element info: {Using=id, value=filter_search}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:317)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:363)
    at org.openqa.selenium.By$ById.findElement(By.java:188)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:309)
    at testScripts.Test.main(Test.java:36)

He comprobado desde el html y tiene el id como filter_search, todavía estoy recibiendo el error hay tal elemento.

Andrei Suvorkov:

Prueba este código:

WebDriverWait wait = new WebDriverWait(driver,10);
driver.get("http://automation.cloudaccess.host/administrator/index.php?option=com_contact&view=contacts");
driver.findElement(By.id("mod-login-username")).sendKeys("admin");
driver.findElement(By.id("mod-login-password")).sendKeys("admin@123");
driver.findElement(By.id("mod-login-password")).submit();
driver.findElement(By.xpath("//button[@onclick=\"Joomla.submitbutton('contact.add');\"]")).click();
driver.findElement(By.id("jform_name")).sendKeys("James");
driver.findElement(By.xpath("//div[@class='input-append']/a")).click();
driver.switchTo().frame("field-user-modal");
Thread.sleep(5000);
WebElement filter = driver.findElement(By.xpath("//input[@id=\"filter_search\"]"));
filter.click();
filter.sendKeys("admin");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.findElement(By.linkText("admin")).click();
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("body > div.modal-backdrop.fade.in")));
driver.findElement(By.xpath("//*[@id='toolbar-apply']/button/span")).click();

que siempre vale la pena para agregar una espera en su prueba, ya que la ejecución de Java es muy rápida y la página web no lo hace. Es por eso que tenemos que esperar hasta DOM estará completamente listo.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=219060&siteId=1
Recomendado
Clasificación