如何在Brave Web浏览器上运行Selenium测试?

时间:2017-11-07 12:47:59

标签: selenium selenium-webdriver selenium-chromedriver browser-automation brave

我正在尝试在Brave网络浏览器上运行一些Selenium测试。我可以使用ChromeDriver通过Selenium启动Brave Web浏览器。但是,没有其他工作,例如我无法让Brave加载某个网页。

由于Brave基于Chromium,我认为这是要走的路。是否有更合适的方式支持Bralen由Selenium驱动?

这是我使用的代码:

AppWidgetManager mAppWidgetManager = context.getSystemService(AppWidgetManager.class);
ComponentName myProvider = new ComponentName(context, MyAppWidgetProvider.class);

if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
    // Create the PendingIntent object only if your app needs to be notified
    // that the user allowed the widget to be pinned. Note that, if the pinning
    // operation fails, your app isn't notified.
    Intent pinnedWidgetCallbackIntent = new Intent( ... );

    // Configure the intent so that your app's broadcast receiver gets
    // the callback successfully. This callback receives the ID of the
    // newly-pinned widget (EXTRA_APPWIDGET_ID).
    PendingIntent successCallback = PendingIntent.createBroadcast(context, 0,
            pinnedWidgetCallbackIntent);

    mAppWidgetManager.requestPinAppWidget(myProvider, null, successCallback);
}

4 个答案:

答案 0 :(得分:1)

记录在案:自从Brave全面使用Chromium(从0.57版开始)以来,这不再是一个问题。现在,我可以使用问题中包含的代码片段对其进行初始化,从而将指令传递给WebDriver。

不过,请务必检查您的ChromeDriver版本是否与Brave Browser版本兼容。

答案 1 :(得分:0)

系统:
macOS Catalina 10.15.2
Python 3.7.4
pytest 5.3.2
硒3.141.0
ChromeDriver 79.0.3945.36
勇敢的1.1.23 Chromium:79.0.3945.88(正式版本)(64位)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/usr/local/bin/chromedriver'
drvr = webdriver.Chrome(options = options, executable_path = driver_path)
drvr.get('https://stackoverflow.com')

参考:
Set chrome browser binary through chromedriver in Python

答案 2 :(得分:0)

在您的情况下,Windows用户路径必须是相对的

System.setProperty("webdriver.chrome.driver","E:\\WEBDRIVER PLUGINS\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions().setBinary("C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe");
WebDriver driver = new ChromeDriver(options);

答案 3 :(得分:0)

感谢@BarneyKelly的魅力! 在python3(Linux Mint 2020)中,我使用了:

def abre_navegador(self):
    # Avenue_Basico.wd = webdriver.Firefox()   # Criar instância do navegador 
    # Avenue_Basico.wd = webdriver.Chrome()   # Criar instância do navegador

    options = Options()
    options.binary_location = '/usr/bin/brave-browser'
    driver_path = '/usr/local/bin/chromedriver'
    self.wd = webdriver.Chrome(options = options, executable_path = driver_path)

再次感谢您的帮助。