Mat*_* M. 4 selenium automation webdriver python-3.x selenium-webdriver
正如文档所述,您可以使用可选参数调用 webdriver.FirefoxProfile()profile_directory
以指向您希望浏览器使用的特定配置文件的目录。我注意到运行这个命令需要很长时间,所以当我查看代码时,它看起来像是在复制指定的配置文件 问题是,配置文件复制需要很长时间(大约 >30 分钟,没有耐心等待它完成。)
我正在使用用户脚本和 selenium 的混合体来为我做一些自动化,所以每次我想测试我的代码时都设置一个新的配置文件会很麻烦。
是改变这种行为以编辑firefox_profile.py
自身的唯一方法(如果是这样,最好的方法是什么?)?
根据GeckoDriver与Firefox的当前实现,使用FirefoxProfile()
如下工作:
如果通过新的Firefox 配置文件启动浏览会话,如下所示:
from selenium import webdriver
myprofile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
Run Code Online (Sandbox Code Playgroud)运行时会创建一个新的rust_mozprofile,如下所示:
1521446301607 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.xFayqKkZrOB8"
Run Code Online (Sandbox Code Playgroud)Of-coarse 成功关闭(即成功调用driver.quit()
)临时rust_mozprofile.xFayqKkZrOB8被完全删除/销毁。
再次在通过现有的Firefox Profile()启动浏览会话的情况下,如下所示:
from selenium import webdriver
myprofile = webdriver.FirefoxProfile(r'C:\Users\AtechM_03\AppData\Roaming\Mozilla\Firefox\Profiles\moskcpdq.SeleniumTest')
driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
Run Code Online (Sandbox Code Playgroud)类似地,运行时会创建一个新的rust_mozprofile,如下所示:
1521447102321 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.2oSwrQwQoby9"
Run Code Online (Sandbox Code Playgroud)同样,在这种情况下,在成功关闭(即成功调用driver.quit()
)时,临时rust_mozprofile.2oSwrQwQoby9 也会被完全删除/销毁。
FirefoxProfile()
挖出一个新的rust_mozprofile所需的时间。也许根据您的问题,复制配置文件的时间跨度(例如> 30 分钟)是纯粹的开销。因此,这将是不可能的使用Firefox的配置文件而不进行的副本rust_mozprofile
。
@Test
. 归档时间: |
|
查看次数: |
7203 次 |
最近记录: |