无法使用Selenium Web驱动程序连接到electronic/CEF应用程序 [英] Unable to connect to the electron / CEF app using selenium web driver
问题描述
我正在尝试使用此示例代码来自动化[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 :
我在localhost收到了以下内容,但没有得到以下内容:
I am getting the following at the localhost , but not the elements :
可检查的WebContents扫描程序ui/appfiles/index.html
Inspectable WebContents scannerui/appfiles/index.html
任何人都可以帮助我了解我要去哪里. 将硒更改为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基于chrome57.因此我将chrome浏览器降级为57,将chrome驱动程序降级为2.26,将硒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 .
仍然无法单击桌面应用程序特定的按钮或文本框.但是能够driver.navigate到Google并执行测试.
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/访问铬元素. 当我在本地主机上打开Chrome浏览器或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 Web驱动程序连接到electronic/CEF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!