자바 스크립트를 실행할 때 경고를 처리하고 싶기 때문에 문제가 있습니다. 모두 Selenium 3.0.1, JDK 1.8 및 Firefox 버전 51.0.1입니다.셀레늄 3 처리되지 않는 경고 처리 자바
내 코드 :
출력에서 public class SeleniumDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Damian6666\\Downloads\\geckodriver\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver();
driver.get("http://wikipedia.org");
JavascriptExecutor jsx = (JavascriptExecutor) driver;
jsx.executeScript("alert('Test Alerts');");
try {
Thread.sleep(3000);
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (Exception e) {
System.out.println(e);
}
}
}
내가 얻을 :
이INFO: Detected dialect: W3C Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to find value field Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700' System info: host: 'Damian', ip: 'xxx.xxx.x.xxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20170125094131, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=6204, browserVersion=51.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt}] Session ID: 912b309c-46a1-4b15-9f9e-f411a6905e87 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.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.RemoteWebDriver.executeScript(RemoteWebDriver.java:537)
at selenium_demo.SeleniumDemo.main(SeleniumDemo.java:35) Picked up _JAVA_OPTIONS: -Xmx1024m Java Result: 1 BUILD SUCCESSFUL (total time: 20 seconds)##
무엇을'capabilities' 객체로 사용하고 있습니까? – forresthopkinsa