Я хочу проверить вход на страницу автоматически, используя selenium и phantomJs. Это мой код, он отлично работает с firefox, но мне нужно использовать phantomJs
try {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "D:\\phantomjs_2_1_1\\bin\\phantomjs.exe");
caps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX,"Y");
caps.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
PhantomJSDriver driver = new PhantomJSDriver(caps);
driver.get("mypage-login");
TimeUnit.SECONDS.sleep(3);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("d:\\sample.png"),true);
System.out.println("FIND ELEMENT [OK] ");
new WebDriverWait(driver, 120).until(
ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"elemId17\"]"))).click();
scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
System.out.println("scrFile := " + scrFile.getAbsolutePath());
FileUtils.copyFile(scrFile, new File("d:\\sample2.png"),true);
TimeUnit.SECONDS.sleep(2);
driver.findElement(By.xpath("//*[@id=\"x-auto-1-input\"]")).sendKeys("username");
driver.findElement(By.xpath("//*[@id=\"x-auto-5-input\"]")).sendKeys("domain");
driver.findElement(By.xpath("//*[@id=\"x-auto-4-input\"]")).sendKeys("password");
new WebDriverWait(driver, 120).until(
ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"elemId98\"]"))).click();
scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("d:\\sample3.png"),true);
if (driver.findElement(By.id("elemId98")) == null)
System.out.println("OK");
System.out.println("KO");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (NullPointerException e) {
e.printStackTrace();
}
finally {
System.out.println("life is good !");
}
Полученные ошибки:
ERROR - 2018-04-24T16:23:41.092Z] Session [cb29bc00-47db-11e8-9aae-df14adbccf9e] - page.onError - msg: Error: com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) : null is not an object (evaluating 'result[1]')
phantomjs://platform/console++.js:263 in error
[ERROR - 2018-04-24T16:23:41.092Z] Session [cb29bc00-47db-11e8-9aae-df14adbccf9e] - page.onError - stack: vkb (mypage:326)
dispatchEvent (:0)
U (:119) $ (:108)
$ (:101)
gh (:141)
sh (:152)
(anonymous function) (:152)
(anonymous function) (:152)
(anonymous function) (:153)
phantomjs://platform/console++.js:263 in error
На скриншоте я вижу что-то не то;после последнего теста (этот код ниже) я добавляю новый TakesScreenshot после сна в течение 10 секунд, результат был таким же, как и раньше на скриншоте №3 'simple3', похоже, что он заблокирован на этом этапе (нажата кнопка входа и анимация длязагрузка индекса или страница ошибки была показана)
if (driver.findElement(By.id("elemId98")) == null)
System.out.println("OK");
System.out.println("KO");
любая дополнительная информация, которую я слушаю и заранее благодарю :)