启动多个驱动程序时出错。在循环中获取命令。我曾观察过有类似问题的人,例如org。openqa。硒。NoSuchSessionException:在使用ChromeDriver Chrome和Java的Selenium自动化测试中没有这样的会话错误,但问题是jdk版本、Chrome版本等等。我可以为每个webdriver实例启动一个get命令,所以我不认为这是我的jdk、chromedriver或selenium版本的问题所在。
String[] referenceID = reference;
String[] commandID = command;
String url = "https://"+website;
System.out.println(Arrays.deepToString(referenceID));
System.out.println(Arrays.deepToString(commandID));
System.out.println("Done");
System.setProperty("webdriver.chrome.driver","D:\\selenium\\libs\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
long waitTime = 0;
long start = System.nanoTime();
int times = gui.getTestAmount();
int i = 0;
boolean reset = false;
driver.get(url);
while(times != 0) {
if(reset) {
try {
Thread.sleep(9000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.get(url);
reset = false;
}
if(commandID[i].equals("Click")) {
driver.findElement(By.xpath(referenceID[i])).click();
System.out.println("Clicked");
}
if (commandID[i].equals("Text")) {
System.out.println("testing text");
String s = referenceID[i];
String id = s.substring(0, s.indexOf(' '));
System.out.println(id);
String content = s.substring(s.indexOf(' ') + 1);
System.out.println(content);
driver.findElement(By.xpath(id)).sendKeys(content);
}
if (commandID[i].equals("Wait")) {
try {
Thread.sleep(Integer.parseInt(referenceID[i])*1000);
waitTime += (Integer.parseInt(referenceID[i])*1000);
System.out.println("Waited");
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Waited done");
}
i++;
if(i>referenceID.length-1) {
System.out.println("in reset");
reset = true;
driver.close();
i=0;
times--;
}
}
错误:
Exception in thread "AWT-EventQueue-0" org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOP-E1N87PDH', ip: 'XXXXXXXX(edited out myself)', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 83.0.4103.116, chrome: {chromedriverVersion: 83.0.4103.39 (ccbf011cb2d2b..., userDataDir: C:\Users\marti\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:56414}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: ea7286c558f6d6969eb16fcb410e68af
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:277)
at data.getInfo.print(getInfo.java:39)
at gui.gui.lambda$5(gui.java:153)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6401)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
我猜问题是在if语句中启动驱动程序。你能试着给司机打电话吗。get(url) 前<代码>时(次!=0)
相信驱动程序在if块完成后变得不活动,因此其他元素没有响应。有关更多解决方案,请参阅此
/**
* Close the current window, quitting the browser if it's the last window currently open.
*/
void close();
您不需要在get之间关闭—每个get都将重新加载浏览器窗口的内容。
我使用Selenium WebDriver和Chrome在我的应用程序中进行功能测试。我已经用rspec、capybara和selenium成功地设置了多个rails应用程序,但我不知道为什么这个不能工作。 问题是:当我第一次运行特性测试时,它会按照计划工作。但是,如果我再次运行它,selenium会崩溃,并出现以下消息: Selenium::WebDriver::Error::NoSuchDri
null 我的脚本中使用的代码: 详细的堆栈跟踪: an 19,2017 6:07:36 PM org.openqa.selenium.remote.ProtocolHandshake创建session信息:尝试双方言会话,假设Postel定律在远程端成立,Jan 19,2017 6:07:37 PM org.openqa.selenium.remote.ProtocolHandshake创建se
我正在尝试使用selenium java代码打开firefox浏览器。 Selenium服务器已启动并正在运行。我尝试使用命令提示符更改selenium服务器端口,并在代码中设置端口,但两者都不起作用。 在错误消息“连接到localhost:6544”中,它每次都试图连接到不同的localhost。有人能看出问题出在哪里吗? 我使用的版本有: firefox 48.0 另外,我的geckodriv
hasNext()的定义是“如果此扫描仪的输入中有另一个标记,则返回true。此方法可能会在等待输入扫描时阻塞。扫描仪不会前进超过任何输入。” 当我把 standardInput.hasNext() 放在 for 循环中时,程序会向无穷大运行。但是如果我把它放在 while-loop 中,它不会运行到无穷大。这两个程序之间的区别在哪里,为什么其中一个有效而另一个无效? for循环: while-l
org.openqa.selenium.NoSuchSessionException:会话ID为空。在调用退出()后使用WebDriver?构建信息:版本:“3.141.59”,修订版:“e82be7d358”,时间:“2018-11-14T08:17:03”系统信息:主机:“DESKTOP-NLBMRCD”,IP:“192.168.1.15”,os.name:“Windows 10”,os.ar
问题内容: 下午全部。当前尝试使用Selenium Webdriver循环浏览页面上的链接列表。具体来说,它是单击链接,从所述页面上抓取一行文本以写入文件,然后返回,然后单击列表中的下一个链接。以下是我所拥有的: 运行时,它会转到初始页面,然后返回主页面,而不是应有的子页面。打印x,我可以看到它递增了三倍而不是一倍。此后它也崩溃。我已经检查了所有的xpath等,并确认列表中的链接数得到了正确的计数