标签: selenium4

WebDriverException:消息:服务 geckodriver 意外退出。状态代码为:在 FreeBSD 监狱中使用 Selenium Geckodriver Firefox 时出现 64 错误

对于一些测试,我设置了一个普通的新 TrueNAS 12.3 FreeBSD Jail 并启动它,然后安装python3firefoxgeckodriverpip使用以下命令:

pkg install python3 firefox geckodriver py38-pip
pip install --upgrade pip
setenv CRYPTOGRAPHY_DONT_BUILD_RUST 1
pip install cryptography==3.4.7
pip install selenium
Run Code Online (Sandbox Code Playgroud)

之后,当我想在 Python 代码中将 Selenium 与 Firefox 一起使用时,它不起作用:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Run Code Online (Sandbox Code Playgroud)

带来

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    self.service.start()
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, …
Run Code Online (Sandbox Code Playgroud)

python selenium freebsd geckodriver selenium4

15
推荐指数
1
解决办法
3万
查看次数

在 Selenium Chrome 驱动程序中禁用缓存

我正在使用 Selenium ChromeDriver 来测量网页的性能。但是默认情况下在 Chrome 驱动程序缓存中是启用的。

选项--disable-application-cache现已弃用https://code.google.com/p/chromium/issues/detail?id=447206

我也可以每次都初始化一个新的驱动程序实例,但不是很方便。

我的问题有没有办法正确禁用缓存?

谢谢!

java selenium google-chrome google-chrome-devtools selenium4

14
推荐指数
2
解决办法
1万
查看次数

如何在 Selenium(使用 Python)中使用 Chrome DevTools 协议来捕获 HTTP 请求和响应?

我知道它Fetch Domain用于此目的,但我不知道如何准确地实现它。在 Selenium python 中,我使用以下代码来启用requestPaused事件的发出。

driver.execute_cdp_cmd("Fetch.enable",{})
driver.get('https://www.example.com')
Run Code Online (Sandbox Code Playgroud)

但我不知道如何处理requestPaused事件(我需要调用 1fulfillRequestcontinueRequest/ continueWithAuth)。结果,我的程序停止工作。如果有人能为我提供一个例子来帮助我理解它是如何工作的,我真的很感激。

selenium google-chrome-devtools fetch-api chrome-devtools-protocol selenium4

10
推荐指数
1
解决办法
1万
查看次数

无法使用 python 中的 selenium 4 的 option.set_preference 加载现有的 firefox 配置文件

我有这段代码可以工作并加载 Firefox 配置文件

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile


ffOptions = Options()
ffProfile = FirefoxProfile(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
ffOptions.profile = ffProfile

driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)

仅它给出以下弃用警告:

firefox_profile 已被弃用,请使用 Options 对象

设置配置文件已被弃用。请使用 set_preference 和 install_addons 方法

为了解决警告,我尝试将代码更新为

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


ffOptions = Options()
ffOptions.set_preference('profile', r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
    
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)

现在没有警告,但浏览器打开时未设置配置文件,它是一个空白配置文件。

selenium python-3.x selenium-firefoxdriver firefox-profile selenium4

10
推荐指数
1
解决办法
6569
查看次数

使用带有 selenium-java-4.0.0 和 chromedriver v85 的开发工具时出现超时异常

我正在尝试使用 selenium 开发工具 java API,对于多种 API 方法,我得到了java.util.concurrent.TimeoutException.

例如,我正在尝试使用Network.clearBrowserCache,它应该可以根据 chromedriver 文档工作:https ://chromedevtools.github.io/devtools-protocol/tot/Network/

我正在clearBrowserCache使用以下代码调用: chromeDriver.getDevTools().send(Network.clearBrowserCache())

它失败了,但同时如果我使用其他类似这样的 devTools 命令: chromeDriver.getDevTools().send(Browser.getVersion())

它正确返回数据。

  • Chrome 版本为:85.0.4183.39
  • Chromedriver 版本为:85.0.4183.87
  • Selenium-java 版本为:4.0.0-alpha-6

java selenium google-chrome-devtools selenium-chromedriver selenium4

9
推荐指数
2
解决办法
713
查看次数

无法找到 CDP 版本 109 的精确匹配,因此返回找到的最接近的版本:使用 Selenium 4x ChromeDriver 109 的无操作实现

我正在尝试执行一个基本的 Selenium Java 程序:

public static void main(String[] args)
{
    System.setProperty("webdriver.chrome.driver", "C:\\BrowserDrivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.quit();
}
Run Code Online (Sandbox Code Playgroud)

具有以下配置:

  • 硒4.x
  • Chrome版本 109.0.5414.75(官方版本)(64 位)(Win 10)
  • Chrome驱动程序109.0.5414.25

Chrome 驱动程序:

ChromeDriver_启动

Chrome 和 ChromeDriver 都是 109.x 版本,尽管程序执行成功,但我仍然在控制台上看到一些警告消息,如下所示:

Starting ChromeDriver 109.0.5414.25 (771113d280dd3dda2fb422a6c805f0eb2b8ee6ed-refs/branch-heads/5414@{#303}) on port 57273
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jan 14, 2023 3:10:47 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
Jan 14, 2023 3:10:47 AM org.openqa.selenium.devtools.CdpVersionFinder …
Run Code Online (Sandbox Code Playgroud)

selenium google-chrome selenium-chromedriver selenium-webdriver selenium4

7
推荐指数
1
解决办法
2万
查看次数

ChromeDriver所需的功能已被弃用,请传入带有options kwarg的Options对象

当我在 python 中启动 Selenium webdriver.Remote 时,我收到此弃用警告,我的 selenium 版本是selenium==4.0.0b2.post1

desired_capabilities has been deprecated, please pass in an Options object with options kwarg
Run Code Online (Sandbox Code Playgroud)

Option 对象应该是什么?我该如何申报?

这是我的代码:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver
import time

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.CHROME
)

driver.get('http://www.google.com/')
Run Code Online (Sandbox Code Playgroud)

python selenium python-3.x selenium-remotedriver selenium4

6
推荐指数
1
解决办法
2万
查看次数

无法从程序集“WebDriver,Version=4.0.0.0,Culture=neutral,PublicKeyToken=null”加载类型“OpenQA.Selenium.Internal.IWrapsElement”

我正在使用 C# 使用 selenium 和 specflow 创建自动化测试。今天,由于日志功能的原因,我不得不将 Selenium.WebDriver 更新到版本 4.0.0-beta4,该功能在以前的版本中存在一个错误,AvailableLogTypes 属性总是抛出空引用异常。更新到selenium 4后,又出现了另一个问题。构建工作正常,没有错误或警告,但是当我运行测试时,会引发以下异常:

Message: 
    System.TypeLoadException : Could not load type 'OpenQA.Selenium.Internal.IWrapsElement' from assembly 'WebDriver, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.

Stack Trace: 
    DefaultPageObjectMemberDecorator.CreateProxyObject(Type memberType, IElementLocator locator, IEnumerable`1 bys, Boolean cache)
    DefaultPageObjectMemberDecorator.Decorate(MemberInfo member, IElementLocator locator)
    PageFactory.InitElements(Object page, IElementLocator locator, IPageObjectMemberDecorator decorator)
    PageFactory.InitElements(Object page, IElementLocator locator)
    PageFactory.InitElements(ISearchContext driver, Object page)
    LoginPageElements.ctor(IWebDriver driver) line 12
    PortalSharedPageSteps.CheckUIElementsOfLoginScreen() line 32
    LoginPageTestSteps.CheckUIElementsOfLoginScreenStep() line 21
    BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
    TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments, TimeSpan& duration) …
Run Code Online (Sandbox Code Playgroud)

c# selenium selenium-chromedriver selenium-webdriver selenium4

6
推荐指数
1
解决办法
9656
查看次数

如何使用 Selenium 4 (devTools) 从网络选项卡获取响应正文

我正在使用 selenium 4 中的 devTools 来检索网络选项卡的响应。

当我获取 url、响应代码、标头等时,

我找不到检索实际响应正文的方法。(我的目的是验证响应中的键值对。)

任何帮助深表感谢。

下面是我的代码的片段。

   devTools.addListener(Network.responseReceived(),
            response -> {
                Response res= response.getResponse();
                System.out.println("URL - " + res.getUrl());
                System.out.println("Status - " + res.getStatus());
                System.out.println("Headers - " + res.getHeaders());
                System.out.println("Header text - " + res.getHeadersText());
            });
Run Code Online (Sandbox Code Playgroud)

selenium devtools google-chrome-devtools selenium4

5
推荐指数
1
解决办法
2万
查看次数

如何禁用DEBUG消息Selenium 4.0

我一直在尝试禁用控制台的调试消息,但无论我做什么,它仍然显示在控制台上。我需要找到一种方法来禁用控制台上 HTTP 请求和响应的持续日志记录。使用的代码:


System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
 

   chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadPath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);

    options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    options.setCapability(ChromeOptions.CAPABILITY, options);
    // options.setCapability(ChromeOptions.CAPABILITY, options);
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    options.addArguments("--disable-logging");
    options.addArguments("--log-level=3");
    options.addArguments("--silent");
    options.setCapability( "goog:loggingPrefs", logPrefs );
    options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    options.setAcceptInsecureCerts(true);
    System.out.println("Launching Google Chrome Browser");
    //ChromeDriverManager.getInstance(CHROME).setup();
    WebDriverManager.chromedriver().setup();
    //   options.merge(cap);



   driver = new ChromeDriver(options);
      
  driver.manage().timeouts().implicitlyWait(TimeOut,TimeUnit.SECONDS);
    driver.manage().window().maximize();

Run Code Online (Sandbox Code Playgroud)

在控制台上

Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
POST /session HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
Content-Length: 1259
Content-Type: application/json; charset=utf-8 …
Run Code Online (Sandbox Code Playgroud)

selenium selenium-webdriver selenium4

5
推荐指数
1
解决办法
3503
查看次数