随着Marionette取代FirefoxDriver,我需要配置我的测试来运行它.我已经下载了二进制文件,但我似乎无法将我的Capybara驱动程序注册配置为实际使用Marionette.
Capybara.register_driver :selenium_firefox do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
capabilities["firefox_binary"] = 'path/to/marionette/renamed/to/wires'
Capybara::Selenium::Driver.new(app, browser: :firefox, desired_capabilities: capabilities)
end
Run Code Online (Sandbox Code Playgroud)
当我开始测试时,我只是得到FF的初始页面,就像我试图在没有牵线木偶的情况下运行它一样.
我有这个例外,因为我用Firefox升级到了3.0 beta.
线程"main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置
我经常更新Firefox和Chrome浏览器,当前版本54.0.1 32位所以要使用哪个版本的Geckodriver.我试过两个版本Geckodriver-v0.18.0 and geckodriver-v0.16.1
为了将来参考,我在哪里可以找到支持的firefox浏览器列表以及各自的geckodriver版本
注意:启动浏览器中没有任何代码更改
以前的代码是使用geckodriver-v0.16.1为较旧的firefox版本现在在更新firefox 54.0.1和Geckodriver-v0.18.0后获得异常:
org.openqa.selenium.firefox.NotConnectedException:45000 ms后无法在端口7055上连接到主机127.0.0.1.Firefox控制台输出:oundUpdates":1,"bootstrap":false,"skinnable":false,"size":3242616,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true "hasBinaryComponents":假 "strictCompatibility":假, "区域设置":[], "targetApplications":[{ "ID": "{ec8030f7-C20A-464f-9b0e-13a3a9e97384}", "MINVERSION":"1.5 ", "MAXVERSION": "9.9"}], "targetPlatforms":[], "multiprocessCompatible":假 "signedState":0, "看到":真 "依赖性":[], "hasEmbeddedWebExtension":假, "mpcOptedOut":假的, "userPermissions":空}
firefox selenium selenium-firefoxdriver selenium-webdriver geckodriver
我正在尝试编写一些防御代码,以防止有人安装旧版本的 geckodriver 时执行脚本。我似乎无法从 webdriver 对象中获取 geckodriver 版本。
我发现的最接近的是driver.capabilities包含 firefox 浏览器版本,但不包含 geckodriver 版本。
from selenium import webdriver
driver = webdriver.Firefox()
pprint(driver.capabilities)
Run Code Online (Sandbox Code Playgroud)
输出:
{'acceptInsecureCerts': True,
'browserName': 'firefox',
'browserVersion': '60.0',
'moz:accessibilityChecks': False,
'moz:headless': False,
'moz:processID': 18584,
'moz:profile': '/var/folders/qz/0dsxssjd1133p_y44qbdszn00000gp/T/rust_mozprofile.GsKFWZ9kFgMT',
'moz:useNonSpecCompliantPointerOrigin': False,
'moz:webdriverClick': True,
'pageLoadStrategy': 'normal',
'platformName': 'darwin',
'platformVersion': '17.5.0',
'rotatable': False,
'timeouts': {'implicit': 0, 'pageLoad': 300000, 'script': 30000}}
Run Code Online (Sandbox Code Playgroud)
浏览器版本和 geckodriver 版本是否可以直接链接?如果没有,我如何从 python 中检查 geckodriver 版本?
我正在尝试使用 python 和 selenium 在 Firefox 无头模式下自动化某些情况。我想,我做了我需要的所有设置,但仍然没有初始化 webdrvier。
我的问题是在执行我的代码后大约 30-60 秒收到异常并且异常消息不清楚实际上消息部分是空的。正如您在无头模式下运行的 geckodriver.log firefox 上看到的那样。
我使用 Firefox 56.0.1、python 3.6、selenium 3.141.0。这是我的代码和日志;
代码:
import os
import time
import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
options = Options()
options.set_headless(True)
dir = "C:\\Python36\\Lib\\site-packages\\selenium\\webdriver\\firefox"
ff_driver_path = dir + "\\geckodriver.exe"
firefox_capabilities = DesiredCapabilities().FIREFOX
firefox_capabilities['marionette'] = True
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla …Run Code Online (Sandbox Code Playgroud) python selenium selenium-firefoxdriver geckodriver firefox-headless
即使我为 Gecko 驱动程序设置了正确的路径,我也遇到了错误。
主要的:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class firstCase {
@Test
static void titleControl(){
System.setProperty("webdriver.gecko.driver", "D:\\Program Exe's\\geckodriver-v0.26.0-win64\\geckodriver.exe"); // Wee need that as Intellij doesn't know where it looks for browser
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
Assert.assertEquals(driver.getTitle(),"Google");
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
1594880236960 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\yasin\\AppData\\Local\\Temp\\rust_mozprofiledXH35Y"
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1594880239039 Marionette INFO Listening on port 49419
1594880239073 Marionette WARN TLS …Run Code Online (Sandbox Code Playgroud) 在将FF9更新为FF10之后,使用Java绑定在Windows 7中使用版本2.15.0和Firefox9时,我遇到了此错误.我尝试在网上建议禁用本机事件,但没有运气.在线搜索了更多解决方案后,我将WebDriver更新到2.17.0版.问题已得到解决,我有时也没有遇到同样的问题.我再次升级到最新版本的WebDriver,2.19.0,问题解决了.现在我在将FF10更新到11之后面临同样的问题.我升级到2.20,但问题占了上风.我禁用了原生事件如下,但我仍然得到错误.
使用Java:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver_enable_native_events", false);
driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)
Stacktrace(当我尝试移动鼠标悬停在元素上时):
org.openqa.selenium.InvalidElementStateException: Cannot perform native interaction: Could not load native events component.
Command duration or timeout: 30.07 seconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_31'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java: 170)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java: 123)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java: 438)
at org.openqa.selenium.remote.ExecuteMethod.execute(ExecuteMethod.java: 47) …Run Code Online (Sandbox Code Playgroud) 我需要使用java读取弹出窗口中显示的警报和确认消息,并在控制台上打印.在从IDE导出selenium记录作为Junit4(WebDriver)java文件时,我的代码是:
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
Run Code Online (Sandbox Code Playgroud)
现在当我尝试使用getAlert或getConfirmation功能如下所示:
@Test
public void testSample() throws Exception {
Alert alert = driver.switchTo().alert();
message = alert.getText();
System.out.println("message is "+message);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
java.lang.NullPointerException
at com.example.tests.Sample.testSample(Sample.java:40)
at com.example.tests.Sample.main(Sample.java:149)
Exception: null
Run Code Online (Sandbox Code Playgroud)
我该如何处理?还有其他方法来阅读弹出消息吗?
我们使用 selenium webdriver dll 设置来运行我的自动化套件。我只在 Firefox 中运行测试时遇到这个问题。Firefox 中的测试运行非常缓慢,加载页面需要 3-4 分钟,但是,当我手动使用 Firefox 浏览器在同一台机器上运行相同的测试时,我没有遇到这种缓慢的情况。有时在 Firefox 上运行自动化时,我们也会看到“连接已重置”页面。此外,相同的测试在 Chrome 和 IE 中运行良好。
我们使用以下环境:
Firefox 版本 28、37(代理设置为使用系统设置)
Webdriver (dll) 版本 2.45
Windows 7的
之前我们使用 Firefox 版本 14,16 和 Webdriver 版本 2.37 在 Windows XP 中运行相同的设置,我们没有遇到这个问题。
我们使用以下代码调用 Firefox:
Proxy proxy = new Proxy();
proxy.Kind = ProxyKind.System;
FirefoxProfile profile = new FirefoxProfile();
profile.SetProxyPreferences(proxy);
RemoteWebDriver dr = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), profile, TimeSpan.FromSeconds(120));
dr.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
dr.Manage().Window.Maximize();
dr.Manage().Cookies.DeleteAllCookies();
dr.Navigate().GoToUrl(WebSiteUrl);
Run Code Online (Sandbox Code Playgroud)
剩余测试步骤......
请有人帮我解决这个问题。
提前致谢。
我正在尝试让 Selenium 在 Ubuntu VM 上工作。我有很多时间这样做。无论我做什么,我总是得到以下对话:
我不需要特别使用任何配置文件。我最初认为 Selenium\Gecko 为其实例创建了一个临时配置文件。以下是我尝试过的所有事情。此外,我还尝试以 sudo 身份运行,并且\或将配置文件的所有权设置nobody为 以及将配置文件目录的权限设置为777. 没有一个被证明是富有成效的。我看过其他关于此的 SO 帖子,但没有一个帖子为我提供了任何导致答案的信息,这显然是我在这里的原因。
# create a new Firefox session
# binary = FirefoxBinary('/snap/bin/firefox')
# binary = FirefoxBinary('/usr/local/bin/geckodriver')
profile = webdriver.FirefoxProfile(profile_directory='/home/jaberwocky/snap/firefox/common/.mozilla/firefox/tm4nraze.selenium')
# profile.set_preference("browser.download.folderList",2)
# profile.set_preference("browser.download.manager.showWhenStarting",False)
# profile.set_preference("browser.download.dir", os.getcwd())
# profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
driver = webdriver.Firefox(firefox_profile=profile)
driver.implicitly_wait(20)
driver.get(base_url)
python_button = driver.find_element_by_class_name('sh-hide')
python_button.click()
Run Code Online (Sandbox Code Playgroud)
硒版本3.141.0
火狐版本65.0.2
Python 版本3.7.2
Linux 发行版 Ubuntu Budgie 18.04.2 LTS
关于这个问题的信息真的不多。我在这里做错了什么?
更新: 我为每次执行 Gecko 找到了一个日志文件。这是它显示的内容:
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload …Run Code Online (Sandbox Code Playgroud)