关于如何关闭丢失了客户端的SeleniumRC服务器上的浏览器和selenium关闭浏览器进程的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于bash–自动启动SeleniumRC服务器、
关于如何关闭丢失了客户端的Selenium RC服务器上的浏览器和selenium关闭浏览器进程的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于bash – 自动启动Selenium RC服务器、Chrome浏览器中的Selenium在线程“main”org.openqa.selenium.WebDriverException中显示异常:等待驱动程序服务器启动超时、php – 执行一段时间后,“无法连接到Selenium RC服务器”、Python3中selenium的浏览器运行环境等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- 如何关闭丢失了客户端的Selenium RC服务器上的浏览器(selenium关闭浏览器进程)
- bash – 自动启动Selenium RC服务器
- Chrome浏览器中的Selenium在线程“main”org.openqa.selenium.WebDriverException中显示异常:等待驱动程序服务器启动超时
- php – 执行一段时间后,“无法连接到Selenium RC服务器”
- Python3中selenium的浏览器运行环境
如何关闭丢失了客户端的Selenium RC服务器上的浏览器(selenium关闭浏览器进程)
假设客户端在RC服务器上启动了selenium会话,但是在会话中间,客户端“消失了”。浏览器将保持打开状态,最终,在经过足够的此类丢弃会话后,将有足够的“孤立”浏览器来降低计算机的速度。
- 如何确定那些浏览器已关闭?
- 为什么协议中没有“保持活动”的部分来确保客户端仍在响应,如果不能终止会话,该怎么办?
答案1
小编典典任何浏览器实例都有一个可以存储的session_id。Python示例:
>>> import selenium>>> browser = selenium.selenium("localhost",4444, "*firefox", "http://www.santiycr.com.ar")>>> browser.start()>>> browser.sessionIdu''b4ad1f1d624e44d9af4200b26d7375cc''
因此,如果您在测试开始时将这些sessionId存储在文件中,然后在测试结束时将其删除,则将有一个日志文件,其中包含测试未正确结束的会话。
现在,使用cron或任何常规执行程序,您可以读取该文件,遍历存储在其中的sessionIds并打开以下网址(使用浏览器,甚至使用您编程语言的http库):
http:// localhost:4444 / selenium-server / driver /?sessionId = THE-SESSION-
ID&cmd = testComplete
这应该够了吧。
编辑:我发现这个问题是如此有趣,以至于在我的博客中创建了有关该解决方案的文章。如果您是python的人,您会发现它很有趣:http :
//www.santiycr.com.ar/djangosite/blog/posts/2009/aug/25/close-remaining-
browsers-from-selenium-
rc
bash – 自动启动Selenium RC服务器
我以为我可以创建一个像这样做的小bash脚本(虽然不起作用):
java -jar ~/bin/selenium-server-standalone-2.0b3.jar & PHPunit --configuration suite.xml && killall java
当然有办法做到这一点吗?使第一行在后台运行,第二行执行直到完成.
或者还有另一种好方法吗? PHPunit是否有先运行流程的工具?
我觉得我需要完全自动化这个,因为如果我忘记启动服务器,PHPunit甚至不会抛出任何错误,它只是跳过测试!
解决方法
PHP代码:exec(“/ path to file / script.sh”);
java代码:进程p = Runtime.getRuntime().exec(/ path to file / script.sh);
同样适用于bat文件.并且该脚本包含启动selenium服务器的命令或直接执行启动服务器的命令.请清楚你的问题和用哪种语言??????
Chrome浏览器中的Selenium在线程“main”org.openqa.selenium.WebDriverException中显示异常:等待驱动程序服务器启动超时
code is correct. added code for time out exception. implicitlyWait added
public class SeleniumClass {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\\\Drivers\\\\chromedriver.exe");
//System.setProperty("webdriver.gecko.driver","F:/Selenium/Jars and Drivers/Drivers/Firefox/geckodriver-v0.29.0-win64/geckodriver.exe");
WebDriver driver = new ChromeDriver();
//WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
driver.get("http://www.google.com");
}
}
,
https://sites.google.com/a/chromium.org/chromedriver/
尝试 - 我下载了最新的稳定版本并且它有效。
php – 执行一段时间后,“无法连接到Selenium RC服务器”
Could not connect to the Selenium RC server.
这是从控制台的日志:
PHPUnit 3.5.15 by Sebastian Bergmann. E Time: 01:56,Memory: 4.00Mb There was 1 error: 1) someTest::testSomething PHPUnit_Framework_Exception: Could not connect to the Selenium RC server. /var/www/path.../someTest.PHP:105 FAILURES! Tests: 1,Assertions: 0,Errors: 1.
我的测试脚本中的第105行:
$this->clickAndWait("//a[text()='Next']");
这里是硒日志:
14:00:40.983 INFO - Command request: click[//a[text()='Next'],] on session 4222e17607254f41a6a52e13d0fd7cc5 14:00:41.205 INFO - Got result: OK on session 4222e17607254f41a6a52e13d0fd7cc5 14:00:41.207 INFO - Command request: waitForPagetoLoad[600000000,] on session 4222e17607254f41a6a52e13d0fd7cc5 14:02:11.328 INFO - Command request: testComplete[,] on session 4222e17607254f41a6a52e13d0fd7cc5 14:02:11.328 INFO - Killing Firefox... 14:02:11.506 INFO - Got result: ERROR: Got a null result on session 4222e17607254f41a6a52e13d0fd7cc5 14:02:11.508 INFO - Got result: OK on session
我尝试使用Selenium Server Standalone 2.19.0,然后用2.20.0 – 相同的结果.
即使在测试中断后,服务器仍在运行.
我的问题是:
为什么这个错误突然发生并意外中断脚本?
PHPUnit 3.5.15
Selenium Server Standalone 2.19.0& 2.20.0
Firefox 3.6.18
Ubuntu 10.04
Python3中selenium的浏览器运行环境
这里只说 Firefox 和 Chrome 浏览器
一、已安装python3和PyCharm Community环境
二、pip 和 selenium 的安装
1、pip 有的在 Python 中是自带的,cmd 窗口输入:pip list 查看;
有可能会提示 pip 版本不匹配,就按提示更新。
2、cmd 窗口 输入:pip install selenium,安装selenium :
这样 pip 和 selenium 安装好了。
三、驱动程序和运行
1、Firefox浏览器:
版本一定要大于48,在:https://github.com/mozilla/geckodriver/releases/,下载 geckodriver.exe 压缩包,解压后放在 Python 安装目录下,如:D:\python37;
2、Chrome浏览器:
1)打开浏览器查看版本:chrome://version/
2)到:http://chromedriver.storage.googleapis.com/index.html? 下载合适的 chromedriver.exe,64位的向下兼容,可以下载32的。解压后放在 Python 安装目录下。
3)运行,以chrome浏览器为例:
没有浏览器驱动程序时会报错:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PATH。
百度这一行错误提示可以找到解决方法,就是上面所说的,正确的下载了驱动程序后可以正常运行。
附:
from selenium import webdriver import time chrome_driver = "D:\python37\chromedriver.exe" driver = webdriver.Chrome(executable_path= chrome_driver) time.sleep(5.5) driver.maximize_window() driver.get(‘http://www.baidu.com/‘) driver.find_element_by_id(‘kw‘).send_keys(‘selenium‘) #driver.refresh() driver.quit()
关于如何关闭丢失了客户端的Selenium RC服务器上的浏览器和selenium关闭浏览器进程的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于bash – 自动启动Selenium RC服务器、Chrome浏览器中的Selenium在线程“main”org.openqa.selenium.WebDriverException中显示异常:等待驱动程序服务器启动超时、php – 执行一段时间后,“无法连接到Selenium RC服务器”、Python3中selenium的浏览器运行环境的相关知识,请在本站寻找。
本文标签: