使用xvfb-run(Selenium WebDriver)发行运行Firefox的问题 - java

我有一个Java应用程序,该应用程序使用Selenium Webdriver登录到站点,检查特定文本,如果找到特定文本,请给我发送电子邮件。我有一项cron作业,该作业每天早晨运行jar文件,并每晚将其停止。

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

xvfb运行--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: [email protected], attempting to register...
*** Item Installed/Upgraded at Install Location: app-profile Item ID: [email protected], 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.<init>(RemoteWebDriver.java:110)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
    at auth.Authenticator.<init>(Authenticator.java:27)
    at reader.ReaderThread.run(ReaderThread.java:70)

奇怪的是,当我使用x2go并登录到debian框时,该程序运行良好。我可以看到Firefox正在打开,登录并按需进行所有操作。

我将2.31版本与Firefox 14配合使用,正如我所说,当我生成桌面会话并登录到该框时,它可以正常工作。

知道为什么它不起作用吗?我想现在已经可以更新到2.32了,但是我不认为这是问题所在,因为在某些情况下它可以正常运行,而在其他情况下则不能。

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

预先感谢您的任何帮助

参考方案

您是否要传递DISPLAY参数?我发现Firefox会在没有它的情况下无法运行(无头运行时)

Xvfb :0 -ac -screen 0 1024x768x24 &

Selenium Webdriver(Java)-查找禁用了属性=“”的元素 - java

我有<input id="test" disabled="">。如何找到具有属性disable =“”的元素。附言:在这种情况下,我不需要使用ID。我想找到一个具有禁用属性的元素。我尝试使用String enbl = Login.driver.findElement(By.cssSelector("…

将ExtentTest的默认设置为FAILED - java

我正在使用extentreports为使用Java和Selenium编写的测试添加报告。我注意到,如果ExtentTest有两个日志“ INFO”和“ PASSED”,则如果未捕获通过日志,则将其视为“通过”。我如何以某种方式更改它,如果未通过测试,它将被自动标记为“失败”? 参考方案 默认情况下,无法更改行为以使测试用例失败。它是一个设计决策,每个测试框架…

如何等待警报框在Selenium中执行操作? - java

我按一个取消按钮,而不是根据我的代码正在检查一些文本。在Chrome和Firefox中,它工作正常,但在IE中,要花一些时间在警报框中执行操作,但代码会移至下一行。因此,我希望一些代码停止运行,直到在警报框上执行该操作,然后再执行下一步。我正在使用硒进行自动化测试。请找到一段代码:Alert al = driver.switchTo().alert(); a…

如何使用带有Java的Selenium WebDriver获得选择的选项 - java

我想使用Selenium WebDriver来获得所选标签或的值下拉,然后在控制台上打印。我可以从下拉列表中选择任何值,但是我无法检索所选值并进行打印:Select select = new Select(driver.findElement(By.id("MyDropDown"))).selectByVisibleText(data[1…

如何在Selenium WebDriver中关闭语言选项框 - java

我想通过Selenium Webdriver跳过语言选择。这可以通过按键盘上的Escape键或单击“保存”按钮来实现。我没有做任何一个。任何人都可以在这方面提供帮助吗?//driver.switchTo().alert(); //button[@id='save_language'] java参考方案 更像是一个警报。尝试使用以下代码:A…