Java Selenide打开IE但可以';t按ID选择元素

Java Selenide打开IE但可以';t按ID选择元素,java,selenium,internet-explorer,selenium-iedriver,selenide,Java,Selenium,Internet Explorer,Selenium Iedriver,Selenide,我们刚刚开始硒化物前端测试。我使用默认值为我们的第一个工作流编写了测试,一切正常(在Chrome中) 现在我想在三大浏览器中运行测试:IE、chrome和firefox 同样,chrome和firefox的一切都很好。但是IE刚刚打开,调用开始url并加载它。之后,第一行代码只是按ID选择一个输入字段并设置一个值。这总是崩溃,我不明白为什么 代码如下: publicstaticvoid登录用户(stringuserid、stringuserpassword){ 开放式(后勤); $(“#user

我们刚刚开始硒化物前端测试。我使用默认值为我们的第一个工作流编写了测试,一切正常(在Chrome中)

现在我想在三大浏览器中运行测试:IE、chrome和firefox

同样,chrome和firefox的一切都很好。但是IE刚刚打开,调用开始url并加载它。之后,第一行代码只是按ID选择一个输入字段并设置一个值。这总是崩溃,我不明白为什么

代码如下:

publicstaticvoid登录用户(stringuserid、stringuserpassword){
开放式(后勤);
$(“#username”).setValue(userId);//此处崩溃
$(“#密码”).setValue(userPassword);
$(“#登录”)。单击();
$(“#mainNav”).should(exist);//等待元素消失
}
在以前的版本中,我使用了
$(By.id(“username”)).setValue(userId)但这并不能很好地工作

也许这就是我开始测试的方式,下面是一些配置测试的代码

@RunWith(参数化的.class)
公共类MyTest{
私有字符串浏览器;
公共MyTest(字符串浏览器){
this.browser=浏览器;
}
@参数化。参数化
公共静态收集数据(){
对象[][]数据={{“ie”}、{“chrome”}、{“firefox”};
返回数组.asList(数据);
}
私有配置myConf=new Config();
@以前
公共作废设置(){
myConf.setUp(浏览器);
}
公共静态void登录用户(字符串userId、字符串userPassword){
开放式(后勤);
$(“#username”).setValue(userId);
$(“#密码”).setValue(userPassword);
$(“#登录”)。单击();
$(“#mainNav”).should(exist);//等待元素消失
}
@试验
公共无效myTest(){
登录用户(用户ID、用户密码);
//一些代码
}
}
公共类配置{
公共静态无效设置(字符串浏览器){
Configuration.browser=浏览器;
Configuration.startMaximized=true;
}
}
提前谢谢

编辑:错误消息:

Aug 02, 2019 11:14:32 AM com.codeborne.selenide.drivercommands.LazyDriver getAndCheckWebDriver
INFORMATION: No webdriver is bound to current thread: 1 - let's create a new webdriver
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Aug 02, 2019 11:14:32 AM java.util.prefs.WindowsPreferences <init>
WARNUNG: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Started InternetExplorerDriver server (64-bit)
3.141.0.0
Listening on port 33492
Only local connections are allowed
Aug 02, 2019 11:14:40 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Detected dialect: W3C
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.webdriver.WebDriverFactory logBrowserVersion
INFORMATION: BrowserName=internet explorer Version=11 Platform=WINDOWS
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.webdriver.WebDriverFactory createWebDriver
INFORMATION: Selenide v. 5.2.4
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.webdriver.WebDriverFactory logSeleniumInfo
INFORMATION: Selenium WebDriver v. 3.14.0 build time: 2018-08-02T20:19:58.91Z
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.drivercommands.CreateDriverCommand createDriver
INFORMATION: Create webdriver in current thread 1: InternetExplorerDriver -> InternetExplorerDriver: internet explorer on WINDOWS (543437e3-a592-4e4a-91e9-fcc55dd1e5ec)
Aug 02, 2019 11:14:44 AM com.codeborne.selenide.impl.ScreenShotLaboratory savePageSourceToFile
WARNUNG: Failed to save page source to 1564737284503.0 because of org.openqa.selenium.NoSuchWindowException: Unable to get browser
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-UF8SMQ23', ip: '192.168.109.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:33492/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 543437e3-a592-4e4a-91e9-fcc55dd1e5ec
Aug 02, 2019 11:14:44 AM com.codeborne.selenide.impl.ScreenShotLaboratory takeScreenshotImage
SCHWERWIEGEND: Failed to take screenshot to 1564737284503.0 because of org.openqa.selenium.NoSuchWindowException: Unable to get browser
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-UF8SMQ23', ip: '192.168.109.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:33492/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 543437e3-a592-4e4a-91e9-fcc55dd1e5ec

Element not found {#username}
Expected: visible or transparent

Page source: file:/C:/Users/Pascal/Dev2/selfservice-test/build/reports/tests/1564737284503.0.html
Timeout: 4 s.
Caused by: NoSuchWindowException: Currently focused window has been closed.
    at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:37)
    at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:100)
2019年8月2日上午11:14:32 com.codeborne.selenide.drivercommands.LazyDriver getAndCheckWebDriver
信息:没有webdriver绑定到当前线程:1-让我们创建一个新的webdriver
SLF4J:未能加载类“org.SLF4J.impl.StaticLoggerBinder”。
SLF4J:默认为无操作(NOP)记录器实现
SLF4J:参见http://www.slf4j.org/codes.html#StaticLoggerBinder 详情请参阅。
2019年8月2日上午11:14:32 java.util.prefs.WindowsPreferences
警告:无法在根0x8000002处打开/创建prefs根节点Software\JavaSoft\prefs。Windows RegCreateKeyEx(…)返回错误代码5。
已启动InternetExplorerDriver服务器(64位)
3.141.0.0
正在侦听端口33492
只允许本地连接
2019年8月2日上午11:14:40 org.openqa.selenium.remote.ProtocolHandshake createSession
信息:检测到的方言:W3C
2019年8月2日上午11:14:40 com.codeborne.selenide.webdriver.WebDriverFactory logBrowserVersion
信息:BrowserName=internet explorer版本=11平台=WINDOWS
2019年8月2日上午11:14:40 com.codeborne.selenide.webdriver.WebDriverFactory createWebDriver
信息:Selenide v。5.2.4
2019年8月2日上午11:14:40 com.codeborne.selenide.webdriver.WebDriverFactory logSeleniumInfo
信息:SeleniumWebDriver v。3.14.0构建时间:2018-08-02T20:19:58.91Z
2019年8月2日上午11:14:40 com.codeborne.selenide.drivercommands.CreateDriverCommand createDriver
信息:在当前线程1中创建webdriver:InternetExplorerDriver->InternetExplorerDriver:WINDOWS上的internet explorer(543437e3-a592-4e4a-91e9-fcc55dd1e5ec)
2019年8月2日上午11:14:44 com.codeborne.selenide.impl.ScreenShotLaboratory savePageSourceToFile
警告:由于org.openqa.selenium.NoSuchWindowException:无法获取浏览器,因此无法将页面源保存到156473284503.0
构建信息:版本:'3.14.0',修订版:'aacccce0',时间:'2018-08-02T20:19:58.91Z'
系统信息:主机:'LAPTOP-UF8SMQ23',ip:'192.168.109.1',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_162'
驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver
功能{AcceptSecureCerts:false,browserName:internet explorer,browserVersion:11,javascriptEnabled:true,pageLoadStrategy:normal,平台:WINDOWS,平台名称:WINDOWS,代理:proxy(),se:ieOptions:{browserAttachTimeout:0,elementScrollBehavior:0,enablePersistentHover:true,ie.BrowserCommandLineSwitchs:,ie.ensureCleanSession:false,ie.fileUploadDialogTimeout:3000,ie.forceCreateProcessApi:false,ignoreProtectedModeSettings:false,IgnoreZoomSet:false,initialBrowserUrl:http://localhost:33492/,nativeEvents:对,RequindowFocus:false},setWindowRect:true,超时:{隐式:0,页面加载:300000,脚本:30000},未处理的PromptBehavior:解除并通知}
会话ID:543437e3-a592-4e4a-91e9-fcc55dd1e5ec
2019年8月2日上午11:14:44 com.codeborne.selenide.impl.ScreenShot实验室拍摄截图
SCHWERWIEGEND:由于org.openqa.selenium.NoSuchWindowException:无法获取浏览器,无法将屏幕截图拍摄到1564727284503.0
构建信息:版本:'3.14.0',修订版:'aacccce0',时间:'2018-08-02T20:19:58.91Z'
系统信息:主机:'LAPTOP-UF8SMQ23',ip:'192.168.109.1',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_162'
驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver
功能{AcceptSecureCerts:false,browserName:internet explorer,browserVersion:11,javascriptEnabled:true,pageLoadStrategy:normal,平台:WINDOWS,平台名称:WINDOWS,代理:proxy(),se:ieOptions:{browserAttachTimeout:0,elementScrollBehavior:0,enablePersistentHover:true,ie.BrowserCommandLineSwitchs:,ie.ensureCleanSession:false,ie.fileUploadDialogTimeout:3000,ie.forceCreateProcessApi:false,ignoreProtectedModeSettings:false,IgnoreZoomSet:fa
System info: host: 'LAPTOP-UF8SMQ23', ip: '192.168.109.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:33492/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 543437e3-a592-4e4a-91e9-fcc55dd1e5ec

Element not found {#username}
Expected: visible or transparent
.
Caused by: NoSuchWindowException: Currently focused window has been closed.
public static void loginUser(String userId, String userPassword) {
    open(loginUrl);
    $("#username").should(exist);
    $("#username").setValue(userId);
    $("#password").setValue(userPassword);
    $("#loginBtn").click();
    $("#mainNav").should(exist);
}