问题
I want to use Selenium WebDriver to run automated tests in a CEF window that is embedded in an application. When i run application with debug console enabled, and then i start my test i'm getting following error:
SessionNotCreatedException: Message: session not created from unknown error: unhandled inspector error: ("code":-32601, "message":"'Target.setAutoAtach' wasn't found")
How can I fix this error? Or there is another way to connect to CEF desktop application?
My C# code:
Cef.Initialize(new CefSettings
{
RemoteDebuggingPort = 55555,
Locale = ResourcesController.GetResource("Locale"),
LogSeverity = LogSeverity.Disable
});
ChromeBrowser = new ChromiumWebBrowser(mainHtml)
{
Dock = DockStyle.Fill,
BrowserSettings = new BrowserSettings
{
FileAccessFromFileUrls = CefState.Enabled,
UniversalAccessFromFileUrls = CefState.Enabled,
},
MenuHandler = new CustomContextMenuHandler()
};
And automation test in python:
import unittest
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import os
CEF_PORT = "55555"
DEBUGGER_ADDRESS = "localhost:{}".format(CEF_PORT)
CHROMEDRIVER_PATH = "C:\chromedriver\chromedriver.exe"
os.environ["PATH"] += os.pathsep + r'C:\chromedriver'
class LoginTest(unittest.TestCase):
window_handle_main = None
def setUp(cls):
options = webdriver.ChromeOptions()
options.debugger_address = DEBUGGER_ADDRESS
def test_button_login_click(self):
WebDriverWait(self.instance, 5).until(ec.presence_of_element_located((By.ID, "btnLogin")))
self.instance.find_element_by_id("btnLogin").click()
def tearDown(self):
self.instance.close()
if __name__ == "__main__":
unittest.main()
I'm using latest version of chromedriver (2.43).
来源:https://stackoverflow.com/questions/53214188/connecting-selenium-driver-to-cef-desktop-application