zoukankan      html  css  js  c++  java
  • 《SeleniumBasic 3.141.0.0

    Firefox有一个Profile的概念,用于设置用户自定义的一些内容。例如设置火狐浏览器启动后的默认主页。

    SeleniumBasic中提供了两种方式,一种是创建FirefoxProfile对象,然后把它赋给FirefoxOptions,接着启动浏览器。

    Private WD As SeleniumBasic.IWebDriver
    Sub Taobao()
        On Error GoTo Err1
        Dim Service As SeleniumBasic.FirefoxDriverService
        Dim Options As SeleniumBasic.FirefoxOptions
        Dim Profile As SeleniumBasic.FirefoxProfile
        Set WD = New SeleniumBasic.IWebDriver
        Set Service = New SeleniumBasic.FirefoxDriverService
        With Service
            .CreateDefaultService driverPath:="E:SeleniumDrivers"
            .HideCommandPromptWindow = True
        End With
        Set Profile = New SeleniumBasic.FirefoxProfile
        With Profile
            .SetPreference "browser.startup.homepage", "https://www.taobao.com/"
            .SetPreference "browser.startup.page", "1"
        End With
        Set Options = New SeleniumBasic.FirefoxOptions
        With Options
            .BrowserExecutableLocation = "C:Program FilesMozilla Firefoxfirefox.exe"
            Set .Profile = Profile
        End With
        WD.New_FirefoxDriver Service:=Service, Options:=Options
    End Sub

    运行上述代码,火狐浏览器自动打开了淘宝主页。

    第二种方式是不创建Profile,直接在FirefoxOptions中使用SetPreference方法。

    Private WD As SeleniumBasic.IWebDriver
    Sub JD()
        On Error GoTo Err1
        Dim Service As SeleniumBasic.FirefoxDriverService
        Dim Options As SeleniumBasic.FirefoxOptions
        Set WD = New SeleniumBasic.IWebDriver
        Set Service = New SeleniumBasic.FirefoxDriverService
        With Service
            .CreateDefaultService driverPath:="E:SeleniumDrivers"
            .HideCommandPromptWindow = True
        End With
        Set Options = New SeleniumBasic.FirefoxOptions
        With Options
            .BrowserExecutableLocation = "C:Program FilesMozilla Firefoxfirefox.exe"
            .SetPreference "browser.startup.homepage", "https://www.jd.com/"
            .SetPreference "browser.startup.page", "1"
        End With
        WD.New_FirefoxDriver Service:=Service, Options:=Options
    End Sub

    上述程序执行后首页是京东网。

    不过第一种方式选项更加丰富,推荐使用。

  • 相关阅读:
    Google黑板报上连载的长文
    sql server2000 数据同步
    sql server 2000 数据同步(2)
    reset sql server express sa password
    Fetion分析之二:服务器地址从何而来——变态的配置文件(转)
    CentOS软件安装血泪经验(转)
    《Unix & Linux 大学教程》(转)
    有关CentOS6的man报错
    linux 命令行学习笔记
    ubuntu 無法掛載ntfs分區
  • 原文地址:https://www.cnblogs.com/ryueifu-VBA/p/13763906.html
Copyright © 2011-2022 走看看