import java.awt.Robot;
import java.awt.event.InputEvent;
public class kiosk {
public static void main(String[] args) {
// As long as you don't move the Chrome window, the Cancel button should appear here.
int x = 410;
int y = 187;
try {
Thread.sleep(7000);// can also use robot.setAutoDelay(500);
Robot robot = new Robot();
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(3000);// can also use robot.setAutoDelay(500);
} catch (AWTException e) {
System.err.println("Error clicking Cancel.");
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
我不确定这对人们来说是否还是个问题。然而,我通读了这篇文章和其他几篇文章,最终使用这段代码在 C # 中工作。我从这篇文章中得到了这一切,可能还有一些与这篇文章相关的文章。
我希望这能有所帮助,它确实解决了我在 c # 控制台应用中的问题。
使用版本52.0.2743.116 m 的 Chrome 浏览器
Selenium 2.9服务器驱动程序
var chromeService = ChromeDriverService.CreateDefaultService(@"C:\Selenium\InstalledServerDrivers\");
var options = new ChromeOptions();
options.AddArgument("--disable-extensions");
IWebDriver driver = new ChromeDriver(chromeService, options);
driver.Url = "http://www.google.com/";
{
"name": "Open and close tab",
"description": "After Chrome starts, open and close a new tab.",
"version": "1.0",
"manifest_version": 2,
"permissions": ["tabs"],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
背景 Js
// This runs when Chrome starts up
chrome.runtime.onStartup.addListener(function() {
// Execute the inner function after a few seconds
setTimeout(function() {
// Open new tab
chrome.tabs.create({url: "about:blank"});
// Get tab ID of newly opened tab, then close the tab
chrome.tabs.query({'currentWindow': true}, function(tabs) {
var newTabId = tabs[1].id;
chrome.tabs.remove(newTabId);
});
}, 5000);
});