問題描述
我正在嘗試使用此示例代碼自動化 [electron-api-demos][1]app.
I am trying to automate [electron-api-demos][1]app using this sample code.
public static void main(String args[]) throws IOException, InterruptedException {
int port = 9223;// Open App
Runtime.getRuntime().exec(
"C:\Program Files\Sample.exe"
, null, new
File("C:\Program Files\Sample"
));
ChromeOptions options = new ChromeOptions();
String remoteDebuggingAddress = "localhost:" + port;
options.setExperimentalOption("debuggerAddress", remoteDebuggingAddress);
options.addArguments("remote-debugging-port=9223");
// options.addArguments("electron-port="+port);
options.setBinary(
"C:\Program Files\Sample.exe");
System.setProperty("webdriver.chrome.driver",
"C:\Users\narays24\eclipse-workspace\xyz\src\demo1\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
System.out.println(driver.getTitle());
String location = "C:\Users\narays24\eclipse-workspace\xyz\src\demo1";
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
String time = dateFormat.format(now);
File dir = new File(location + time);
if (!dir.exists())
{
dir.mkdir();
}
else
{
//System.out.println("directory already exists");
//Do nothing
}
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(location + time + "\screen1.png"));
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
我可以訪問該應用程序并獲取屏幕截圖.我無法通過以下端口訪問 cef:
I am able to access the app and get a screenshot. I am not able to access the cef through the below port :
http://localhost:9223/
我在 localhost 得到以下內容,但不是元素:
I am getting the following at the localhost , but not the elements :
可檢查的 WebContents 掃描儀ui/appfiles/index.html
Inspectable WebContents scannerui/appfiles/index.html
誰能幫我理解我哪里出錯了.將 selenium 更改為 alpha 后,我可以毫無錯誤地運行它.
Can anyone help me understand where I am going wrong. After changing the selenium to alpha , I am able to run this with out errors .
更新
我能夠導航到 google 并在 cef 中實現自動化.但我無法控制或對應用程序的菜單欄或按鈕或文本框執行任何操作.
I am able to navigate to google and automate in cef . But I am not able to control or perform any actions on application's menu bar or buttons or text boxes.
我的 cef 基于 chrome 57 .所以我將 chrome 瀏覽器降級為 57 ,將 chrome 驅動程序降級為 2.26 ,將 selenium Java 庫降級為 2.36 .
My cef is based on chrome 57 .so I downgraded the chrome browser to 57 , chrome driver to 2.26 and selenium Java libraries to 2.36 .
我仍然無法單擊桌面應用程序特定的按鈕或文本框.但我能夠驅動程序.導航到谷歌并執行測試.
Still I am not able to click on desktop application specific buttons or text boxes. But am able to driver.navigate to google and perform tests.
有人可以幫忙嗎?我正在使用 Java ,硒
Can anyone help here? I am using Java , selenium
我也試過上面提到的電子申請,還是沒有運氣
I also tried on electron application as mentioned above, still no luck
推薦答案
@DebanjanB,謝謝您的幫助.將 selenium 的版本更改為 alpha 后,我可以無錯誤地連接到應用程序.我現在正在使用以下代碼:
@DebanjanB, Thanks for the help. After I changed the version of the selenium to alpha , I am able to connect to the app with out errors. I am using the following code now :
public static void main(String args[]) throws IOException, InterruptedException {
int port = 9223;
// Open App
Runtime.getRuntime().exec(
"C:\Program Files\SampleApp.exe", null,
new File("C:\Program Files\SampleApp"));
ChromeOptions options = new ChromeOptions();
String remoteDebuggingAddress = "localhost:" + port;
options.setExperimentalOption("debuggerAddress", remoteDebuggingAddress);
options.addArguments("remote-debugging-port=9223");
options.setBinary(
"C:\Program Files\SampleApp.exe");
System.setProperty("webdriver.chrome.driver",
"C:\Users\xyz\eclipse-workspace\xyz\src\demo1\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
System.out.println(driver.getTitle());
}
問題是我無法在 http://localhost:9223/ 訪問 chromium 中的元素當我在本地主機上打開 chromium 或 chrome 瀏覽器時,會顯示以下文本.通常需要一個鏈接.鏈接或 WebElement 不顯示.
The issue is I am not able to access the elements in chromium at http://localhost:9223/ When I open the chromium or chrome browser at teh local host the following text is displayed . Normally a link is expected . Link or the WebElements are not displayed.
可檢查的 WebContents 掃描儀ui/appfiles/index.html
Inspectable WebContents scannerui/appfiles/index.html
這篇關于無法使用 selenium 網絡驅動程序連接到電子/CEF 應用程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!