處理使用phantomJS警告我有如下一個Java代碼,當我通過PhantomJs收到「不支持的命令異常」運行,但它工作正常,如果我通過Firefox和Chrome運行: -無法在Java中
注:有了phantomJs,我們可以在下面的代碼中執行到第3步。我在很多博客中搜索過,但這些答案並沒有解決我的問題。
1. cvvField.sendKeys(cvcData);
2. proceedToPayBtn.click();
3. Reporter.log("Card details are submitted from payment UI page");
4. Alert a1=driver.switchTo().alert();
5. Reporter.log("Alert with text:"+a1.getText());
6. a1.accept();
這裏cvvField和proceedToPayBtn是WebElements,cvcData的值是「111」。
錯誤日誌: -
org.openqa.selenium.UnsupportedCommandException: Invalid Command Method -
{"headers":{"Accept-Encoding":"gzip,deflate","Cache-Control":"no-cache","Connection":"Keep-Alive","Host":"localhost:30462","User-Agent":"Apache-HttpClient/4.5.1 (Java/1.8.0_101)"},"httpVersion":"1.1","method":"GET","url":"/alert_text","urlParsed":{"anchor":"","query":"","file":"alert_text","directory":"/","path":"/alert_text","relative":"
/alert_text","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/alert_text","queryKey":{},"chunks":["alert_text"]},"urlOriginal":"/session/9e392a50-ce79-11e6-b24a-2b12cf1ec4d6/alert_text"}
命令持續時間或超時:31 milliseconds
我在上面的代碼如下編輯,但同樣的錯誤是coming.Please建議
if (driver instanceof PhantomJSDriver)
{
JavascriptExecutor je = (JavascriptExecutor) driver;
je.executeScript("window.alert = function(){};");
je.executeScript("window.confirm = function(){return true;};");
System.out.println("Alert has been handled");
} else {
Alert a1 = driver.switchTo().alert();
a1.accept();
}
我是GE在輸出控制檯中輸入「警報已處理」,但不處理警報。
謝謝@Sumit amble – Aaditya
我已經編輯了上面的代碼,如下所示,但它仍然不工作,顯示相同的錯誤。 – Aaditya