xvfb运行java脚本_使用xvfb-run运行firefox(Selenium WebDriver)

我有一个

Java应用程序,使用Selenium Webdriver登录到一个站点,检查特定的文本,如果找到它们给我发电子邮件.我有一个cron作业,每天早上运行jar文件,每晚都停止它.

它使用firefox但运行无头,这是命令

xvfb-run –auto-servernum –server-num = 0 nohup /usr/bin/java -jar A.jar

当它试图打开Firefox时,抛出以下内容:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:

*** Item Installed via directory addition to Install Location: app-global Item ID: {972ce4c6-7e08-4474-a285-3208198ce6fd}, attempting to register...

*** Item Installed/Upgraded at Install Location: app-global Item ID: {972ce4c6-7e08-4474-a285-3208198ce6fd}, attempting to register...

*** Blocklist::_loadBlocklist: no XML File found

*** ... success, item is compatible

*** Item Installed via directory addition to Install Location: app-profile Item ID: fxdriver@googlecode.com, attempting to register...

*** Item Installed/Upgraded at Install Location: app-profile Item ID: fxdriver@googlecode.com, attempting to register...

*** ... success, item is compatible at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)

at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)

at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92)

at auth.Authenticator.(Authenticator.java:27)

at reader.ReaderThread.run(ReaderThread.java:70)

奇怪的是,当我使用x2go并登录debian框时,程序运行正常.我可以看到Firefox打开,登录并尽其所能.

我正在使用Firefox 14的2.31版本,正如我所说,当我产生桌面会话并登录到盒子时它可以正常工作.

知道为什么它不起作用吗?我想我现在可以更新到2.32但是我不认为这是问题,因为它在某些情况下可以正常工作而在其他情况下并不适用.

P.S如果我让它在我的Windows eclipse实例中运行,它没有任何问题.

在此先感谢您的帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Linux上使用XvfbSelenium结合Java来进行自动化测试是一种常见的方法。首先,你需要安装XvfbSelenium服务器。你可以通过克隆一个名为xvfb-selenium-server的存储库来安装Xvfb Selenium服务器。在Ubuntu 12.04服务器上,你可以使用以下命令进行克隆: $ cd /opt/ $ git clone https://github.com/Tomohiro/xvfb-selenium-server.git 然后,你需要安装一些依赖项。具体步骤可以参考相关资源。 接下来,你需要在Java项目中添加Selenium的Maven依赖。你可以在你的pom.xml文件中添加以下代码来添加Selenium的依赖: ```xml <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> ``` 这样就可以在你的Java项目中使用Selenium了。 关于你提到的Google,我不清楚你具体指的是什么。如果你是想使用Selenium来操作Google搜索或其他Google相关的操作,你可以参考Selenium的官方文档或其他相关教程来学习如何使用Selenium进行这些操作。 总结起来,使用XvfbSeleniumJava和Google的组合可以实现在Linux上进行自动化测试。你需要安装XvfbSelenium服务器并配置Java项目的依赖。然后,你可以使用Selenium来进行各种操作,包括与Google相关的操作。希望这些信息对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [xvfb-selenium-server:Xvfb 上的 Headless Selenium 服务器项目](https://download.csdn.net/download/weixin_42115074/20000194)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [web自动化测试(java+seleium)环境安装](https://blog.csdn.net/qq_43532386/article/details/127916749)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值